#ifdef PM_DEBUG

#include "common.h"
#include "system/pm_str.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/arc_util.h"
#include "system/bmp_cursor.h"
#include "fld_bmp.h"
#include "fieldmap.h"
#include "field_common.h"
#include "system/fontproc.h"

#include "debug_saito.h"
#include "d_saito_st.h"

#include "system/brightness.h"

#include "camera_move_test.h"

#include "fieldsys.h"

#include "field_event.h"
#include "mapdefine.h"
#include "worldmap.h"
#include "player.h"
#include "zonedata.h"

#include "ev_mapchange.h"
#include "eventdata.h"		//ゾーン毎のイベントデータ参照のため

//↓ポケモン関連
#include "system/buflen.h"

#include "system/msgdata_util.h"

#include "msgdata/msg_debug_saito.h"
#include "msgdata/msg.naix"

#include "encount_set.h"

#include "savedata/encount.h"
#include "move_pokemon_def.h"

#include "move_pokemon.h"
#include "field/field_place_name.h"
#include "system/snd_tool.h"

#include "generate_zone.h"

#include "encount_define.h"
#include "arc/encdata_ex.naix"
#include "system/zukanwork.h"

#include "pair_poke.h"


//ポケスロン
#include "application/pokethlon_frame.h"
#include "savedata/pkthln_svdata.h"
#include "ev_pokemon.h"	//for EvPoke_GetLivingPokemonTop

#define DEBUG_PKTH_EVT_NUM	(10)
#define DEBUG_PKTH_CRS_NUM	(11)
#define DEBUG_PKTH_EVT_LOOP_NUM	(4)

#define DEBUG_MEDAL_NUM	(5)
#define DEBUG_MEDAL_LOOP_NUM	(DEBUG_MEDAL_NUM+1)
#define DEBUG_SPEC_LOOP_NUM	(5)
#define DEBUG_SPEC_MAX	(4)

//記念撮影
#include "field_picture.h"
#include "../fielddata/eventdata/zone_t23evc.h"

//三体選択
#include "demo/first_poke_select.h"

#include "system/pm_overlay.h"
FS_EXTERN_OVERLAY( debug_pair_poke );

#define	FDBG_DEBUG_PL		(FLD_SYSFONT_PAL)	//パレットナンバー

#define DISP_LINE_MAX	(9)

#define HEAPID_D_SAITO	(HEAPID_BASE_APP)

#define DEBUG_CONT_TIME	(30)


//--------------------------------------------------------------
/// 斉藤(優)さん、保坂のみのデフォルトの種目をフック
//==============================================================
#ifdef DEBUG_ONLY_FOR_masafumi_saitou
	#define DEBUG_PKTH_EVT_HOOK
	#define DEBUG_HOOK_EVT_CODE (PKTHLN_EVT_BREAK)
#endif

#ifdef DEBUG_ONLY_FOR_genya_hosaka
	#define DEBUG_PKTH_EVT_HOOK
	#define DEBUG_HOOK_EVT_CODE (PKTHLN_EVT_DROP)
#endif


//----------------------------------------------------------------------------
//	構造体定義
//----------------------------------------------------------------------------

typedef struct _DEBUG_WORK_DATA{
	struct _FIELDSYS_WORK * fsys;
	GF_CAMERA_PTR camera;
	STRBUF	*StrBuf;
	u8 camera_tbl_no;

	GF_BGL_BMPWIN	win;
	s8	rod;
	u8	MovePokeInfoNo;	//0〜2
	s8	zone_idx;
}DEBUG_WORK_DATA;

//ポケスロン競技用
typedef struct D_PKTH_WORK_tag
{
	struct _FIELDSYS_WORK * fsys;
	GF_BGL_BMPWIN	win;
	BMPCURSOR * cursor;
	int CurPoint;

	s16 ThlnEntryIdx;
	u16 MedalMonsNo;

	int ContTime;
}D_PKTH_WORK;

typedef void (*DRAW_FUNC)( DEBUG_WORK_DATA* );

static const GF_CAMERA_PARAM TestOrgCamera[] =
{
	{
		/*0x30aec1*/0x29aec1,
		{
			-0x29fe,0,0
		},
		GF_CAMERA_PERSPECTIV,
		0x05c1,
		0	//dummy
	},								//0
	{
		0x29aec1,
		{-0x127e,0,0},
		GF_CAMERA_PERSPECTIV,
		0x281,
		3	//near_far shift
	}								//1

};

//------------------------------------------------------------------------------
//	global
//------------------------------------------------------------------------------

BOOL Debug_SetPokeChgEvent(FIELDSYS_WORK * fsys, int trg);

//------------------------------------------------------------------------------
//	extern
//------------------------------------------------------------------------------
extern u8 HC_DebugCheckHeight(const fx32 inX, const fx32 inZ, MHI_CONST_PTR inMap3DInfo, const BOOL inDetail);

extern PICTURE_DATA  TestPicData;

extern PAIR_POKE_DBG PairPokeDbg;

extern int DebugLegFldDemoFlg;

//---------------------------------------------------------------------------
//	static 変数
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
//	static 関数
//---------------------------------------------------------------------------
static void InitDebugWindow(DEBUG_WINDOW_DATA *wp);
static void DebugListFree(TCB_PTR tcb,void* work);
static void DebugWindowExit(TCB_PTR tcb,void* work);
static void DebugListControlTask(TCB_PTR tcb,void* work);

static void ChangeStressFlg(TCB_PTR tcb,void *work);

static void MBMapSetExit(TCB_PTR tcb,void* work);


static void SetCameraDebugWindow(TCB_PTR tcb,void *work);
static void SetupCameraInfoWindow(TCB_PTR tcb,void *work);
static void SetupCameraListWindow(TCB_PTR tcb,void *work);

static void SetCamera(TCB_PTR tcb,void *work);
///static void SetupPokeAnmWindow(TCB_PTR tcb,void *work);
static void DebugWinFishing(TCB_PTR tcb,void *work);
static void DebugWinMovePoke(TCB_PTR tcb,void *work);

static void SetupFishingRod(TCB_PTR tcb,void *work);
static void SetupFishingProb(TCB_PTR tcb,void *work);

static void SetupMovePokeInfo(TCB_PTR tcb,void *work);
static void DebugWinMovePokeName(TCB_PTR tcb,void *work);
static void SetupEntryMovePoke(TCB_PTR tcb,void *work);
static void SetupMovePokeZoneChgWin(TCB_PTR tcb,void *work);

//高さ変更
static void SetPlayerHeightChangeTask(TCB_PTR tcb,void *work);

//高さデバッグ
static void DebugCheckHeightGrid(TCB_PTR tcb,void *work);
static void DebugCheckHeightBlock(TCB_PTR tcb,void *work);

//大量発生
static void DebugGenerate(TCB_PTR tcb,void *work);
static void DebugStartGenerate(TCB_PTR tcb,void *work);
static void SetupGeneZoneInfoWin(TCB_PTR tcb,void *work);

//サファリ
static void DebugSafari(TCB_PTR tcb,void *work);

//AGB
static void DebugSetAgbVer(TCB_PTR tcb,void *work);
static void DebugAgbVer(TCB_PTR tcb,void *work);

//吹き出し
static void SetupBallonTypeNum(TCB_PTR tcb,void *work);

//ポケスロンコール
static void CallPokethlon(TCB_PTR tcb,void *work);
static void DebugWinPokethlon(TCB_PTR tcb,void *work);
static void SetupPkthlnDFlag(TCB_PTR tcb,void *work);
static void SetPkthlnDFlagWindow(struct _FIELDSYS_WORK * fsys);
static void PkthlnDFlagDispTask(TCB_PTR tcb,void* work);
static void DrawPkthlnDFlag(DEBUG_WORK_DATA *d_work);
static void SetupPkthlnEvtWindow(TCB_PTR tcb,void *work);
static void SetPkthlnEvtWindow(struct _FIELDSYS_WORK * fsys);
static void PkthlnEvtDispTask(TCB_PTR tcb,void* work);
static void DrawPkthlnEvt(D_PKTH_WORK *wk);
static void SetupPkthlnCrsWindow(TCB_PTR tcb,void *work);
static void SetPkthlnCrsWindow(struct _FIELDSYS_WORK * fsys);
static void PkthlnCrsDispTask(TCB_PTR tcb,void* work);
static void DrawPkthlnCrs(D_PKTH_WORK *wk);

static void SetupPkthlnPointWindow(TCB_PTR tcb,void *work);
static void SetPkthlnPointWindow(struct _FIELDSYS_WORK * fsys);
static void PkthlnPointDispTask(TCB_PTR tcb,void* work);
static void DrawPkthlnPoint(D_PKTH_WORK *wk);

static void SetupMedalWindow(TCB_PTR tcb,void *work);
static void SetMedalWindow(struct _FIELDSYS_WORK * fsys);
static void MedalDispTask(TCB_PTR tcb,void* work);
static void DrawMedal(D_PKTH_WORK *wk);

static void SetupSpecWindow(TCB_PTR tcb,void *work);
static void SetSpecWindow(struct _FIELDSYS_WORK * fsys);
static void SpecDispTask(TCB_PTR tcb,void* work);
static void DrawSpec(D_PKTH_WORK *wk);

static void SetupSpecDFlag(TCB_PTR tcb,void *work);
static void SetSpecDFlagWindow(struct _FIELDSYS_WORK * fsys);
static void SpecDFlagDispTask(TCB_PTR tcb,void* work);
static void DrawSpecDFlag(DEBUG_WORK_DATA *d_work);

static void SetupInfinityFlg(TCB_PTR tcb,void *work);
static void SetInfinityFlgWindow(struct _FIELDSYS_WORK * fsys);
static void InfinityFlgDispTask(TCB_PTR tcb,void* work);
static void DrawInfinityFlg(DEBUG_WORK_DATA *d_work);

static void SetupEneStopFlg(TCB_PTR tcb,void *work);
static void SetEneStopFlgWindow(struct _FIELDSYS_WORK * fsys);
static void EneStopFlgDispTask(TCB_PTR tcb,void* work);
static void DrawEneStopFlg(DEBUG_WORK_DATA *d_work);

static void SetCountStopNeary(TCB_PTR tcb,void *work);
static void SetRnkCountStopNeary(struct _FIELDSYS_WORK * fsys);

//波紋テスト
static void CallWave(TCB_PTR tcb,void *work);

//記念撮影
static void SetPictureDebugWindow(TCB_PTR tcb,void *work);
static void TakePicture(TCB_PTR tcb,void *work);
///static void ViewPicture(TCB_PTR tcb,void *work);
static void TakePictureNoMdl(TCB_PTR tcb,void *work);
static void TakePictureWithRocket(TCB_PTR tcb,void *work);
static void TakePictureWithLeader(TCB_PTR tcb,void *work);

//ロケット団に変装
static void ChangeRocket(TCB_PTR tcb,void *work);

//3体選択
static void CallPokeSelect(TCB_PTR tcb,void *work);

//リニア
static void DebugWinLinear(TCB_PTR tcb,void *work);
static void CallLinearDemoK(TCB_PTR tcb,void *work);//コガネコール
static void CallLinearDemoY(TCB_PTR tcb,void *work);//ヤマブキコール

//船
static void DebugWinShip(TCB_PTR tcb,void *work);
static void CallShipDemoA(TCB_PTR tcb,void *work);//アサギコール
static void CallShipDemoK(TCB_PTR tcb,void *work);//クチバコール

//連れ歩き
static void SetPairPokeViewMode(TCB_PTR tcb,void *work);
static BOOL ChangePairPokeEvt(GMEVENT_CONTROL * event);
static BOOL ChangePairPokeColEvt(GMEVENT_CONTROL * event);

//伝説デモ
static void SetFldLegDemoFlg(TCB_PTR tcb, void *work);
static void SetFldLegDemoFlgWindow(struct _FIELDSYS_WORK * fsys);
static void FldLegDemoFlgTask(TCB_PTR tcb,void* work);
static void DrawFldLegFlg(DEBUG_WORK_DATA *wk);

static void DebugPairPoke(TCB_PTR tcb, void *work);
static void DebugPairPokeOverlayCB(void);

//----------------------------------------------------------------------------
//	リスト項目名
//----------------------------------------------------------------------------

//--------------------------------------------------------------------------
//	項目と実行関数のリスト
//--------------------------------------------------------------------------


static const ID_PARAM DebugMenuMainList[] = {
	{ D_SAITO_MSG01, (u32)SetCamera },
///	{ D_SAITO_MSG02, (u32)SetCamera, },
#if 0
    { D_SAITO_MSG03, (u32)DebugCheckHeightBlock },
    { D_SAITO_MSG04, (u32)DebugCheckHeightGrid },
#endif
    { D_SAITO_MSG05, (u32)SetCameraDebugWindow },
#if 0
    { D_SAITO_MSG06, (u32)SetPlayerHeightChangeTask },

///	{ D_SAITO_MSG09, (u32)SetupPokeAnmWindow },
	{ D_SAITO_MSG10, (u32)DebugWinFishing },
#endif
	{ D_SAITO_MSG11, (u32)DebugWinMovePoke },
	{ D_SAITO_MSG12, (u32)DebugGenerate },
///	{ D_SAITO_MSG13, (u32)DebugSafari},
#if 0
	{ D_SAITO_MSG14, (u32)DebugSetAgbVer },
///	{ D_SAITO_MSG14, (u32)SetupBallonTypeNum },
	{ D_SAITO_POKE_SEL, (u32)CallPokeSelect },
#endif
	{ D_SAITO_PKTHLN,(u32)DebugWinPokethlon },
///	{ D_SAITO_MSG02, (u32)CallWave },
#if 0
	{ D_SAITO_PICTURE,(u32)SetPictureDebugWindow },
	{ D_SAITO_ROCKET,(u32)ChangeRocket },
	{ D_SAITO_LINEAR_DEMO,(u32)DebugWinLinear },
	{ D_SAITO_SHIP_DEMO,(u32)DebugWinShip },
#endif
	{ D_SAITO_PAIR_POKE_VIEW,(u32)SetPairPokeViewMode },
#if 0
	{ D_SAITO_ROM_VER,(u32)SetFldLegDemoFlg },
#endif
	{ D_SAITO_PAIR_POKE,(u32)DebugPairPoke },
};

static const ID_PARAM DebugCameraMenuList[] = {
	{ D_SAITO_MSG07, (u32)SetupCameraInfoWindow },
	{ D_SAITO_MSG08, (u32)SetupCameraListWindow },
};
#if 0
static const ID_PARAM DebugFishingMenuList[] = {
	{ D_SAITO_FISH01, (u32)SetupFishingRod },
	{ D_SAITO_FISH02, (u32)SetupFishingProb },
};
#endif

static const ID_PARAM DebugMovePokeMenuList[] = {
	{ D_SAITO_MP01, (u32)SetupMovePokeInfo },
	{ D_SAITO_MP02, (u32)DebugWinMovePokeName },
	{ D_SAITO_MP03, (u32)SetupEntryMovePoke },
};

static const ID_PARAM DebugMovePokeNameList[] = {
	{ D_SAITO_MP_RAI, (u32)SetupMovePokeZoneChgWin },
	{ D_SAITO_MP_EN, (u32)SetupMovePokeZoneChgWin },
	{ D_SAITO_MP_ASU, (u32)SetupMovePokeZoneChgWin },
	{ D_SAITO_MP_OSU, (u32)SetupMovePokeZoneChgWin },
};

static const ID_PARAM DebugGeneMenuList[] = {
	{ D_SAITO_GENE01, (u32)DebugStartGenerate },
	{ D_SAITO_GENE02, (u32)SetupGeneZoneInfoWin },
};

#if 0
static const ID_PARAM DebugAgbMenuList[] = {
	{ D_SAITO_AGB00, (u32)DebugAgbVer },
	{ D_SAITO_AGB01, (u32)DebugAgbVer },
	{ D_SAITO_AGB02, (u32)DebugAgbVer },
	{ D_SAITO_AGB03, (u32)DebugAgbVer },
	{ D_SAITO_AGB04, (u32)DebugAgbVer },
	{ D_SAITO_AGB05, (u32)DebugAgbVer },
};

static const ID_PARAM DebugPictureMenuList[] = {
	{ D_SAITO_PIC_TAKE, (u32)TakePicture },
///	{ D_SAITO_PIC_VIEW, (u32)ViewPicture },
	{ D_SAITO_PIC_TAKE2, (u32)TakePictureNoMdl },
	{ D_SAITO_PIC_TAKE3, (u32)TakePictureWithRocket },
	{ D_SAITO_PIC_TAKE4, (u32)TakePictureWithLeader },
};
#endif

static const ID_PARAM DebugPkthlnMenuList[] = {
	{ D_SAITO_PKTHLN_START, (u32)CallPokethlon },
	{ D_SAITO_PKTHLN_FLAG, (u32)SetupPkthlnDFlag },
	{ D_SAITO_PKTHLN_EVT, (u32)SetupPkthlnEvtWindow },
	{ D_SAITO_PKTHLN_CRS, (u32)SetupPkthlnCrsWindow },
	{ D_SAITO_PKTHLN_POINT, (u32)SetupPkthlnPointWindow },	//スロンポイント
	{ D_SAITO_PKTHLN_MEDAL, (u32)SetupMedalWindow },	//メダル
	{ D_SAITO_PKTHLN_SPEC, (u32)SetupSpecWindow },	//スペック
	{ D_SAITO_PKTHLN_SPEC_DBG, (u32)SetupSpecDFlag },	//スペックデバッグ
	{ D_SAITO_PKTHLN_INFINITY, (u32)SetupInfinityFlg },	//時間無限
	{ D_SAITO_PKTHLN_ENE_STOP, (u32)SetupEneStopFlg },	//敵AI停止
	{ D_SAITO_PKTHLN_COUNT_STOP, (u32)SetCountStopNeary },	//カンスト手前
};

#if 0
static const ID_PARAM DebugLinearMenuList[] = {
	{ D_SAITO_LINEAR_KOGANE, (u32)CallLinearDemoK },
	{ D_SAITO_LINEAR_YAMABUKI, (u32)CallLinearDemoY },
};

static const ID_PARAM DebugShipMenuList[] = {
	{ D_SAITO_SHIP_ASAGI, (u32)CallShipDemoA },
	{ D_SAITO_SHIP_KUCHIBA, (u32)CallShipDemoK },
};
#endif

//---------------------------------------------------------------------------
//  ウィンドウ設定
//---------------------------------------------------------------------------
//メインウィンドウ
static const BMPWIN_DAT	MainDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	14,21,
	FDBG_DEBUG_PL,8
};

//カメラウィンドウ
static const BMPWIN_DAT	CameraDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	14,5,
	FDBG_DEBUG_PL,8
};

//釣り
static const BMPWIN_DAT	FishingDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	16,7,
	FDBG_DEBUG_PL,8
};
//移動ポケモン
static const BMPWIN_DAT	MovePokeDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	12,7,
	FDBG_DEBUG_PL,8
};
//移動ポケモン名
static const BMPWIN_DAT	MovePokeNameDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	8,8,
	FDBG_DEBUG_PL,8
};
//大量発生
static const BMPWIN_DAT	GeneDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	10,6,
	FDBG_DEBUG_PL,8
};
//AGB
static const BMPWIN_DAT	AgbDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	10,14,
	FDBG_DEBUG_PL,8
};

//記念撮影
static const BMPWIN_DAT	PictureDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	16,12,
	FDBG_DEBUG_PL,8
};

//ポケスロンメニュー
static const BMPWIN_DAT	PkthlnDebugListWindowData = {
	GF_BGL_FRAME3_M,
	0,1,
	16,22,
	FDBG_DEBUG_PL,8
};



//リスト作成
void MakeBmpList(struct _FIELDSYS_WORK *fsys, const int inNum, ID_PARAM const *list, BMPWIN_DAT const * win_dat, OVERLAY_CALL_BACK callback)
{
	TCB_PTR pTcb;
	DEBUG_WINDOW_DATA *wp;

	BMPLIST_HEADER bmplist_h = {
		//MainDebugList,		//表示文字データポインタ
		NULL,				//表示文字データポインタ
		NULL,				//カーソル移動ごとのコールバック関数
		NULL,		//１行ごとのコールバック関数
		NULL,		//GF_BGL_BMPWIN *
		0,//リスト項目数
		0,//表示最大項目数
		2,					//ラベル表示Ｘ座標
		12,					//項目表示Ｘ座標
		1,					//カーソル表示Ｘ座標
		8,					//表示Ｙ座標
		FBMP_COL_WHITE,		//文字色
		FBMP_COL_BLACK,		//背景色
		FBMP_COL_BLK_SDW,	//文字影色
		0,					//文字間隔Ｘ
		1,					//文字間隔Ｙ
		BMPLIST_LRKEY_SKIP,	//ページスキップタイプ
		FONT_SYSTEM,			//文字指定
		0,					//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
		NULL,				//*work
	};

	wp = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WINDOW_DATA));
	if(wp == NULL){
		//ワークエリアが取得できなければ何もしない
		OS_Printf("map_num debug menu crate failed\n");
		return;
	}
	memset(wp,0,sizeof(DEBUG_WINDOW_DATA));

	wp->fsys = fsys;

	//デバッグメニュー用変数初期化
	InitDebugWindow(wp);

	//メイン処理タスク追加
	pTcb = TCB_Add(DebugListControlTask,wp,0);


	wp->ld = BMP_MENULIST_Create( inNum, HEAPID_D_SAITO );
	{
		MSGDATA_MANAGER* msgman;
		int i;

		msgman = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
		for(i=0; i<inNum; i++)
		{
			BMP_MENULIST_AddArchiveString( wp->ld, msgman,
					list[i].str_id, list[i].param );
		}
		MSGMAN_Delete(msgman);
	}

	//BITMAPメニュー追加
	GF_BGL_BmpWinAddEx(fsys->bgl,&wp->win,win_dat);
	//BMPリスト設定
	bmplist_h.count = inNum;
	if (DISP_LINE_MAX < inNum){
		bmplist_h.line = DISP_LINE_MAX;
	}else{
		bmplist_h.line = inNum;
	}
	OS_Printf("disp=%d\n",inNum);
	bmplist_h.list = wp->ld;
	bmplist_h.win = &wp->win;
	wp->lw = BmpListSet(&bmplist_h,0,0,HEAPID_D_SAITO);

	wp->OverlayCallBack = callback;
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//ウィンドウ構築
static void SetWindow(	struct _FIELDSYS_WORK * fsys, TCB_FUNC t_func, DRAW_FUNC d_func,
						u8 posx, u8 posy, u8 sizx, u8 sizy 	)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(t_func,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, posx, posy, sizx, sizy, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//確率フラグ表示
	d_func(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//===============================================================================
//	ウィンドウ共通
//===============================================================================
//初期化
static void InitDebugWindow(DEBUG_WINDOW_DATA *wp)
{
	wp->debug_list = 0;
	wp->debug_cursor = 0;
}
//リストの開放処理
static void DebugListFree(TCB_PTR tcb,void* work)
{
	DEBUG_WINDOW_DATA	*wp;

	wp = (DEBUG_WINDOW_DATA*)work;

	//BMPウィンドウOFF
	GF_BGL_BmpWinOff(&wp->win);

	//BMPリスト破棄
	BmpListExit( wp->lw,&wp->debug_list,&wp->debug_cursor );
	//BMPWindow消去
	GF_BGL_BmpWinDel( &wp->win );
	return;
}

//デバッグウィンドウを解放
void FreeDebugWindow(TCB_PTR tcb,void* work)
{
	//リストの開放処理
	DebugListFree(tcb,work);
	//ワークメモリ開放
	sys_FreeMemoryEz(work);
}

//デバッグウィンドウを解放(メモリ解放無し)
static void FreeDebugWindowNoFreeMem(TCB_PTR tcb,void* work)
{
	//リストの開放処理
	DebugListFree(tcb,work);
}
//デバッグウィンドウ終了
static void DebugWindowExit(TCB_PTR tcb,void* work)
{
	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();//OBJ等の動作停止解除
	return;
}
//リストコントロール
static void DebugListControlTask(TCB_PTR tcb,void* work)
{
	s32	ret_code;
	TCB_FUNC	func;
	DEBUG_WINDOW_DATA	*wp;

	wp = (DEBUG_WINDOW_DATA*)work;

	ret_code = BmpListMain(wp->lw);
	//キー操作判定
	if(sys.trg & PAD_BUTTON_A){
		if(ret_code){
			BMP_MENULIST_Delete( wp->ld );	//とりあえず
			func = (TCB_FUNC)ret_code;
			func(tcb,work);
		}
		return;
	}
	//メニューキャンセル
	if(sys.trg & PAD_BUTTON_B){
		if (wp->OverlayCallBack != NULL){
			wp->OverlayCallBack();
		}
		BMP_MENULIST_Delete( wp->ld );	//とりあえず
		DebugWindowExit(tcb,work);
		return;
	}
}

//================================================================================
//	カメラ情報
//================================================================================
static void DrawCameraInfo(GF_CAMERA_PTR camera_ptr,GF_BGL_BMPWIN	*win, const u8 inNo)
{
	CAMERA_ANGLE angle;
	STRBUF *str;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	GF_BGL_BmpWinDataFill( win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	str = STRBUF_Create(10, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(16,HEAPID_D_SAITO);

	MSGMAN_GetString(man, D_SAITO_CAM_INFO01 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );
	MSGMAN_GetString(man, D_SAITO_CAM_INFO02 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 1*16, MSG_ALLPUT, NULL );
	MSGMAN_GetString(man, D_SAITO_CAM_INFO03 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 2*16, MSG_ALLPUT, NULL );
	MSGMAN_GetString(man, D_SAITO_CAM_INFO04 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 3*16, MSG_ALLPUT, NULL );
	MSGMAN_GetString(man, D_SAITO_CAM_INFO05 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 4*16, MSG_ALLPUT, NULL );
	MSGMAN_GetString(man, D_SAITO_CAM_INFO06 ,msg_buf);
	GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 5*16, MSG_ALLPUT, NULL );

	STRBUF_SetHexNumber(	str, GFC_GetCameraDistance(camera_ptr), 8,
							NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, 7*8, 0, MSG_ALLPUT, NULL );

	angle = GFC_GetCameraAngle(camera_ptr);

	STRBUF_SetHexNumber(str, angle.x, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 1*16, MSG_ALLPUT, NULL );
	STRBUF_SetHexNumber(str, angle.y, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 2*16, MSG_ALLPUT, NULL );
	STRBUF_SetHexNumber(str, angle.z, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 3*16, MSG_ALLPUT, NULL );

	STRBUF_SetHexNumber(str, GFC_GetCameraPerspWay(camera_ptr), 8,
						NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 4*16, MSG_ALLPUT, NULL );

	if (GFC_GetCameraView(camera_ptr) == GF_CAMERA_PERSPECTIV){
		MSGMAN_GetString(man, D_SAITO_CAM_INFO07 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 8*8, 5*16, MSG_ALLPUT, NULL );
	}else{
		MSGMAN_GetString(man, D_SAITO_CAM_INFO08 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 8*8, 5*16, MSG_ALLPUT, NULL );
	}

	{
		//ニア・ファー
		int near,far;
		near = GFC_GetCameraNear(camera_ptr)/FX32_ONE;
		far = GFC_GetCameraFar(camera_ptr)/FX32_ONE;

		MSGMAN_GetString(man, D_SAITO_CAM_INFO09 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 6*16, MSG_ALLPUT, NULL );
		MSGMAN_GetString(man, D_SAITO_CAM_INFO10 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 7*16, MSG_ALLPUT, NULL );
		STRBUF_SetNumber(str, near, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 6*16, MSG_ALLPUT, NULL );
		STRBUF_SetNumber(str, far, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 7*16, MSG_ALLPUT, NULL );
	}
	{
		//バインドターゲットとの差分
		VecFx32 look_at = GFC_GetLookTarget(camera_ptr);
		const VecFx32 *bind = GFC_GetBindTargetVecPtr(camera_ptr);
		MSGMAN_GetString(man, D_SAITO_CAM_INFO11 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 8*16, MSG_ALLPUT, NULL );
		MSGMAN_GetString(man, D_SAITO_CAM_INFO12 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 9*16, MSG_ALLPUT, NULL );
		MSGMAN_GetString(man, D_SAITO_CAM_INFO13 ,msg_buf);
		GF_STR_PrintSimple(win, FONT_SYSTEM, msg_buf, 1*8, 10*16, MSG_ALLPUT, NULL );

		STRBUF_SetHexNumber(str, look_at.x-bind->x, 8,
						NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 8*16, MSG_ALLPUT, NULL );
		STRBUF_SetHexNumber(str, look_at.y-bind->y, 8,
						NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 9*16, MSG_ALLPUT, NULL );
		STRBUF_SetHexNumber(str, look_at.z-bind->z, 8,
						NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 10*16, MSG_ALLPUT, NULL );
	}

	{
		//カメラテーブル番号
		STRBUF_SetNumber(str, inNo, 2, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(win, FONT_SYSTEM, str, 8*8, 11*16, MSG_ALLPUT, NULL );
	}

	STRBUF_Delete( msg_buf );
	STRBUF_Delete( str );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( win );

}

//カメラ用ウィンドウセット
static void SetCameraDebugWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//カメラウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugCameraMenuList),DebugCameraMenuList, &CameraDebugListWindowData, NULL);

}
//カメラリストウィンドウ表示中タスク
static void CameraListDispTask(TCB_PTR tcb,void* work)
{
	BOOL flg;
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	flg = FALSE;
	if ( sys.trg & PAD_KEY_RIGHT ){
		flg = TRUE;
		if (d_work->camera_tbl_no == NELEMS(TestOrgCamera)-1){
			d_work->camera_tbl_no=0;
		}else{
			d_work->camera_tbl_no++;
		}
	}else if (sys.trg & PAD_KEY_LEFT){
		flg = TRUE;
		if (d_work->camera_tbl_no == 0){
			d_work->camera_tbl_no = NELEMS(TestOrgCamera)-1;
		}else{
			d_work->camera_tbl_no--;
		}
	}

	if (flg == TRUE){
		//カメラパラメータ変更
		//カメラセット
		{
			GFC_InitCameraTDA(
				Player_VecPosPtrGet(d_work->fsys->player),
				TestOrgCamera[d_work->camera_tbl_no].Distance,		// 距離
				&TestOrgCamera[d_work->camera_tbl_no].Angle,		//
				TestOrgCamera[d_work->camera_tbl_no].PerspWay,		// 投射栄の角度
				TestOrgCamera[d_work->camera_tbl_no].View,
				TRUE,
				d_work->camera);
			if (TestOrgCamera[d_work->camera_tbl_no].dummy==1){
				GFC_SetCameraClip(FX32_ONE*150, FX32_ONE*1160,d_work->camera);
			}else if(TestOrgCamera[d_work->camera_tbl_no].dummy==2){
				GFC_SetCameraClip(FX32_ONE*150, FX32_ONE*1735,d_work->camera);
			}else if(TestOrgCamera[d_work->camera_tbl_no].dummy==3){
				VecFx32 move = {0x12000,0,-0x2c000};
				GFC_SetCameraClip(FX32_ONE*150, FX32_ONE*900,d_work->camera);
				GFC_ShiftCamera(&move,d_work->camera);
			}
			GFC_CopyCameraTracePtr(d_work->fsys->camera_ptr, d_work->camera);
		}
		//カメラ情報表示
		DrawCameraInfo(d_work->camera,&d_work->win,d_work->camera_tbl_no);
	}

	if (sys.trg & PAD_BUTTON_B){
		//カメラ反映
		GFC_CopyCamera(d_work->camera,d_work->fsys->camera_ptr);
		//カメラ削除
		GFC_FreeCamera(d_work->camera);
		//カメラアタッチ
		GFC_AttachCamera(d_work->fsys->camera_ptr);

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

//カメラ情報ウィンドウ表示中タスク
static void CameraInfoDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	if (sys.trg & PAD_BUTTON_B){

		//カメラ削除
		GFC_FreeCamera(d_work->camera);
		//カメラアタッチ
		GFC_AttachCamera(d_work->fsys->camera_ptr);

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

//カメラ情報用ウィンドウ構築
static void SetCameraInfoWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->camera_tbl_no = 0;

	d_work->fsys = fsys;
	//カメラ生成
	d_work->camera = GFC_AllocCamera(HEAPID_D_SAITO);
	GFC_CopyCamera(d_work->fsys->camera_ptr, d_work->camera);
	GFC_AttachCamera(d_work->camera);
	//メイン処理タスク追加
	pTcb = TCB_Add(CameraInfoDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 18, 24, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//カメラ情報表示
	DrawCameraInfo(d_work->camera,&d_work->win, d_work->camera_tbl_no);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//カメラリスト用ウィンドウ構築
static void SetCameraListWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->camera_tbl_no = 0;

	d_work->fsys = fsys;
	//カメラ生成
	d_work->camera = GFC_AllocCamera(HEAPID_D_SAITO);
	{
		GFC_InitCameraTDA(
				Player_VecPosPtrGet(fsys->player),
				TestOrgCamera[0].Distance,		// 距離
				&TestOrgCamera[0].Angle,		//
				TestOrgCamera[0].PerspWay,		// 投射栄の角度
				TestOrgCamera[0].View,
				TRUE,
				d_work->camera);
		GFC_CopyCameraTracePtr(d_work->fsys->camera_ptr, d_work->camera);
	}
	GFC_AttachCamera(d_work->camera);
	//メイン処理タスク追加
	pTcb = TCB_Add(CameraListDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 18, 24, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//カメラ情報表示
	DrawCameraInfo(d_work->camera,&d_work->win, d_work->camera_tbl_no);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//カメラ情報用ウィンドウセット
static void SetupCameraInfoWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//カメラ情報ウィンドウ構築
	SetCameraInfoWindow(fsys);
}

//カメラリスト用ウィンドウセット
static void SetupCameraListWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//カメラ情報ウィンドウ構築
	SetCameraListWindow(fsys);
}

static void CameraControlTask(TCB_PTR tcb,void *work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;
	(void)CameraInput(d_work->camera);


	if ( (sys.cont & PAD_BUTTON_B) && (sys.trg & PAD_BUTTON_X) ){

		//カメラセット
		{
			GFC_InitCameraTDA(
				Player_VecPosPtrGet(d_work->fsys->player),
				TestOrgCamera[0].Distance,		// 距離
				&TestOrgCamera[0].Angle,		//
				TestOrgCamera[0].PerspWay,		// 投射栄の角度
				TestOrgCamera[0].View,
				TRUE,
				d_work->camera);

			GFC_CopyCameraTracePtr(d_work->fsys->camera_ptr, d_work->camera);
		}
	}

	if (sys.cont & PAD_BUTTON_L){
		//カメラ反映
		GFC_CopyCamera(d_work->camera,d_work->fsys->camera_ptr);
		//カメラ削除
		GFC_FreeCamera(d_work->camera);
		//カメラアタッチ
		GFC_AttachCamera(d_work->fsys->camera_ptr);
		//ワークメモリ開放
		sys_FreeMemoryEz(d_work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

static void SetCamera(TCB_PTR tcb,void *work)
{
	DEBUG_WORK_DATA *d_work;

	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;

	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));

	d_work->fsys = wp->fsys;
	//カメラ生成
	d_work->camera = GFC_AllocCamera(HEAPID_D_SAITO);
	GFC_CopyCamera(d_work->fsys->camera_ptr, d_work->camera);
	GFC_AttachCamera(d_work->camera);

	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//タスクセット
	TCB_Add(CameraControlTask,d_work,0);

}

//-----------------------------------------------------------------------------
//	アクセス関数
//-----------------------------------------------------------------------------
//デバッグメインウィンドウ構築関数
void DBGSAI_MapNumDebugListSet(struct _FIELDSYS_WORK * fsys)
{
	MakeBmpList(fsys, NELEMS(DebugMenuMainList), DebugMenuMainList, &MainDebugListWindowData, NULL);
}

static int DebugPlayerHeightOfs = 0;

//高さを変える
static void HeightChangeTask(TCB_PTR tcb,void* work)
{
	VecFx32 *ofs;
	const VecFx32 *vec;

	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	ofs = Player_VecDrawOffsPtrGet( d_work->fsys->player );
	vec = Player_VecPosPtrGet(d_work->fsys->player);
//	BLACT_WORK* bl_w;
//	bl_w = BLACT_WorkGet(FldBlActIdx, map3Ddata->actor[0].actorno);

	if (sys.trg & PAD_KEY_UP){
		OS_Printf("デバッグ：高さUP\n");
		DebugPlayerHeightOfs++;
		ofs->y += (FX32_ONE/4);
//		bl_w->Matrix.y+= (FX32_ONE/4);
	}else if (sys.trg & PAD_KEY_DOWN){
		OS_Printf("デバッグ：高さDOWN\n");
		DebugPlayerHeightOfs--;
		ofs->y -= (FX32_ONE/4);
//		bl_w->Matrix.y-= (FX32_ONE/4);
	}

	if (sys.trg & PAD_BUTTON_X){
		//リセット
		OS_Printf("デバッグ：高さリセット\n");
		DebugPlayerHeightOfs = 0;
		ofs->y = vec->y;
		ofs->y += (FX32_ONE*16);

//		bl_w->Matrix.y = map3Ddata->actor[0].global.y;
//		bl_w->Matrix.y+=(FX32_ONE*16);
	}

	if (sys.trg & PAD_BUTTON_B){
		sys_FreeMemoryEz(work);
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

//高さ変更タスクセット
static void SetPlayerHeightChangeTask(TCB_PTR tcb,void *work)
{
	DEBUG_WORK_DATA *d_work;

	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));

	d_work->fsys = wp->fsys;
	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//タスクセット
	TCB_Add(HeightChangeTask,d_work,0);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
#define ATTR_DISP_W_NUM	(3)
#define ATTR_DISP_H_NUM	(3)
#define ATTR_ONE_DISP_SIZE (5)
typedef struct {
	GF_BGL_BMPWIN	win;//BMP
	GF_BGL_BMPWIN	win2;//BMP
	FIELDSYS_WORK * fsys;
}ATTR_CONT;

//アトリビュート情報表示
static void DispAttrInfo(ATTR_CONT *work)
{
	GF_BGL_BmpWinDataFill( &work->win, 0x0f );
	GF_BGL_BmpWinDataFill( &work->win2, 0x0f );

	//自機の位置のアトリビュートを表示
	{
		int grid_x,grid_z,height;
		int base_x,base_z;
		int x,z;
		u8 i,j;
		u8 disp_ofs_x;
		BOOL rc;
		u8 attr;

		MSGDATA_MANAGER* man;
		STRBUF *msg_buf;
		STRBUF* str;

		man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
		msg_buf = STRBUF_Create(16,HEAPID_D_SAITO);
		str = STRBUF_Create(4, HEAPID_D_SAITO);

		//自機グリッド座標を取得
		grid_x = Player_NowGPosXGet( work->fsys->player );
		grid_z = Player_NowGPosZGet( work->fsys->player );
		{
			VecFx32 vec;
			Player_VecPosGet( work->fsys->player, &vec );
			height = vec.y/(FX32_ONE*16);
		}

		base_x = grid_x-1;
		base_z = grid_z-1;

		for (i=0;i<3;i++){
			z = base_z+i;
			for(j=0;j<3;j++){
				disp_ofs_x = ATTR_ONE_DISP_SIZE*j*8;
				x = base_x+j;
				//アトリビュート取得
				rc = GetHitAttr(work->fsys, x, z);

				if (rc){
					MSGMAN_GetString(man, D_SAITO_ATTR01 ,msg_buf);
					GF_STR_PrintSimple(&work->win, FONT_SYSTEM, msg_buf, disp_ofs_x, i*16, MSG_ALLPUT, NULL );
				}else{
					MSGMAN_GetString(man, D_SAITO_ATTR02 ,msg_buf);
					GF_STR_PrintSimple(&work->win, FONT_SYSTEM, msg_buf, disp_ofs_x, i*16, MSG_ALLPUT, NULL );
				}

				attr = GetAttributeLSB(work->fsys, x, z);
				STRBUF_SetHexNumber( str, attr, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
				GF_STR_PrintSimple(&work->win, FONT_SYSTEM, str, disp_ofs_x+2*8, i*16, MSG_ALLPUT, NULL );
			}
		}

		//自機グリッドから、ブロック座標、ブロック内ローカル座標を計算
		{
			int block_x,block_z;
			u8 local_x,local_z;
			u8 ofs = 6*8;
			u8 item_ofs = 3*8;
			block_x = grid_x/32;
			block_z = grid_z/32;
			local_x = grid_x%32;
			local_z = grid_z%32;

			MSGMAN_GetString(man, D_SAITO_ATTR03 ,msg_buf);
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, msg_buf, 0, 0, MSG_ALLPUT, NULL );
			MSGMAN_GetString(man, D_SAITO_ATTR04 ,msg_buf);
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, msg_buf, 0, 16, MSG_ALLPUT, NULL );
			MSGMAN_GetString(man, D_SAITO_ATTR05 ,msg_buf);
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, msg_buf, 0, 32, MSG_ALLPUT, NULL );

			STRBUF_SetNumber( str, block_x, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, str, ofs+0, 0, MSG_ALLPUT, NULL );
			STRBUF_SetNumber( str, block_z, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, str, ofs+item_ofs, 0, MSG_ALLPUT, NULL );
			STRBUF_SetNumber( str, local_x, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, str, ofs+0, 16, MSG_ALLPUT, NULL );
			STRBUF_SetNumber( str, local_z, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, str, ofs+item_ofs, 16, MSG_ALLPUT, NULL );
			STRBUF_SetNumber( str, height, 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
			GF_STR_PrintSimple(&work->win2, FONT_SYSTEM, str, ofs+0, 32, MSG_ALLPUT, NULL );

		}
		STRBUF_Delete(str);
		STRBUF_Delete( msg_buf );
		MSGMAN_Delete( man );
	}

	GF_BGL_BmpWinOn( &work->win );
	GF_BGL_BmpWinOn( &work->win2 );
}

//アトリビュート確認コントロール
static void DebugCheckAttrControlTask(TCB_PTR tcb,void* work)
{
	ATTR_CONT	*wp;
	wp = (ATTR_CONT*)work;
	//メニューキャンセル
	if(sys.trg & PAD_BUTTON_B){
		GF_BGL_BmpWinOff( &wp->win );
		GF_BGL_BmpWinDel( &wp->win );
		GF_BGL_BmpWinOff( &wp->win2 );
		GF_BGL_BmpWinDel( &wp->win2 );
		//ワークメモリ開放
		sys_FreeMemoryEz(work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
		return;
	}
}

//アトリビュート確認
void DBGSAI_CheckAttribute(struct _FIELDSYS_WORK * fsys)
{
	ATTR_CONT *d_work;
	int size_w,size_h;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(ATTR_CONT));
	d_work->fsys = fsys;

	size_w = ATTR_ONE_DISP_SIZE*ATTR_DISP_W_NUM;
	size_h =  2*ATTR_DISP_H_NUM;

	GF_BGL_BmpWinAdd( fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0,
			size_w,size_h, 1, 1 );

	GF_BGL_BmpWinAdd( fsys->bgl,&d_work->win2,GF_BGL_FRAME3_M, 0, 18,
			6+3*2, 3*2, 1, 1+size_w*size_h );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//メイン処理タスク追加
	TCB_Add(DebugCheckAttrControlTask,d_work,0);
	//情報表示
	DispAttrInfo(d_work);
}

static BOOL DebugCheckHeightGridIn(	struct _FIELDSYS_WORK * fsys,
									const int inGridX,
									const int inGridZ,
									const BOOL inRoop,
									const BOOL inDetail)
{
	u8 idx;
	u8 rc;
	int i,j;
	fx32 base_x,x,base_z,z;
	MHI_CONST_PTR  height_info;
	fx32 x_ofs,z_ofs;
	int count;
	BOOL block_result;
	int non_height_count;

	//グリッドをfx32に
	base_x = inGridX*16*FX32_ONE;
	base_z = inGridZ*16*FX32_ONE;

	idx = GetNowLocalIndex(fsys->map_cont_dat);
	height_info = GetDivMapHeightInfo(fsys->map_cont_dat,idx);

	{
		//ブロックオフセット分を減算
		x_ofs = (((inGridX/32)*BLOCK_GRID_W)+(BLOCK_GRID_W/2))*16*FX32_ONE;
		z_ofs = (((inGridZ/32)*BLOCK_GRID_H)+(BLOCK_GRID_H/2))*16*FX32_ONE;
		base_x -= x_ofs;
		base_z -= z_ofs;
	}

	count = 0;
	block_result = FALSE;
	non_height_count = 0;
	for(i=0;i<16;i++){
		x = base_x+(i*FX32_ONE);
		for(j=0;j<16;j++){
			z = base_z+(j*FX32_ONE);
			rc = HC_DebugCheckHeight(x, z, height_info, inDetail);
			if (rc==1){
				if (inRoop == FALSE){
					//return TRUE;
					block_result = TRUE;
				}else{
					OS_Printf("ユニット内座標%d,%dは複数の高さを持っています\n",i,j);
					count++;
				}
			}else if(rc==2){
				if (inRoop == FALSE){
					if (block_result != TRUE){
						//return FALSE;
						block_result = FALSE;
					}
				}else{
					OS_Printf("ユニット内座標%d,%dは同じ高さを複数持っています\n",i,j);
				}

			}else if(rc==3){
				non_height_count++;
				if (inRoop == FALSE){
					if (block_result != TRUE){
						//return FALSE;
						block_result = FALSE;
					}
				}else{
					OS_Printf("ユニット内座標%d,%dは高さを持っていません\n",i,j);
				}
			}
		}
	}
	if (inRoop == FALSE){
		if (non_height_count!=256){//１グリッド全て高さが無かったとき以外
			OS_Printf("グリッド内に高さのない場所があります\n");
		}
		return block_result;
	}

	if (inDetail){
		OS_Printf("グリッド内には、複数の高さを持つユニットが%d箇所存在します\n",count);
	}

	if (count>0){
		return TRUE;
	}else{
		return FALSE;
	}
}

static void DebugCheckHeightGrid(TCB_PTR tcb,void *work)
{
	DEBUG_WINDOW_DATA *wp = (DEBUG_WINDOW_DATA *)work;
	//高さデバッグ
	{
		u8 idx;
		int i,j;
		int grid_x,grid_z;
		VecFx32 base,vec;
		fx32 x_ofs,z_ofs;
		MHI_CONST_PTR  height_info;
		BOOL rc;

		Player_VecPosGet(wp->fsys->player, &base);

		//基点
		base.x-=(8*FX32_ONE);
		base.z-=(8*FX32_ONE);

		grid_x = Player_NowGPosXGet( wp->fsys->player );
		grid_z = Player_NowGPosZGet( wp->fsys->player );
		{
			int local_x,local_z;
			local_x = grid_x%32;
			local_z = grid_z%32;

			OS_Printf("\n//ブロック内グリッド座標%d,%dの高さをチェック\n",local_x,local_z);
		}

		DebugCheckHeightGridIn(wp->fsys,
				grid_x,
				grid_z,
				TRUE, TRUE);

	}
	DebugWindowExit(tcb,work);
}

static void DebugCheckHeightBlock(TCB_PTR tcb,void *work)
{
	DEBUG_WINDOW_DATA *wp = (DEBUG_WINDOW_DATA *)work;
	//高さデバッグ
	{
		int i,j;
		int block_x,block_z;
		int base_grid_x,base_grid_z;
		BOOL rc;
		int count;
		block_x = Player_NowGPosXGet( wp->fsys->player )/BLOCK_GRID_W;
		block_z = Player_NowGPosZGet( wp->fsys->player )/BLOCK_GRID_H;

		OS_Printf("\n//ブロック%d,%dの高さをチェック\n",block_x,block_z);

		count = 0;
		for(i=0;i<32;i++){
			base_grid_x = block_x*32+i;
			for(j=0;j<32;j++){
				base_grid_z = block_z*32+j;
				rc = DebugCheckHeightGridIn(wp->fsys, base_grid_x, base_grid_z, FALSE, FALSE);
				if (rc){
					OS_Printf("高さ２層以上のグリッド：%d,%d\n",i,j);
					count++;
				}
			}
		}
		OS_Printf("２層以上の高さを持つグリッドを%d個発見\n",count);
	}

	DebugWindowExit(tcb,work);
}

#if 0
/////////////////////釣り
extern u8 DebugFishProbFlg;
//釣りメイン
static void DebugWinFishing(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugFishingMenuList), DebugFishingMenuList, &FishingDebugListWindowData, NULL);
}

//釣竿ナンバー表示
static void DrawFishingRod(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, d_work->rod, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

//ロッド表示中タスク
static void RodDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if (sys.repeat & PAD_KEY_UP){
		d_work->rod++;
		if (d_work->rod>2){
			d_work->rod = 0;
		}
	}else if(sys.repeat & PAD_KEY_DOWN){
		d_work->rod--;
		if (d_work->rod<0){
			d_work->rod = 2;
		}
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawFishingRod(d_work);
	}

	if (sys.trg & PAD_BUTTON_A){
		BOOL rc;

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
		rc = DebugSetFishingEncount( d_work->fsys, d_work->rod );
		OS_Printf("fishing = %d\n",rc);

		sys_FreeMemoryEz((void *)work);
	}else if (sys.trg & PAD_BUTTON_B){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugFishingMenuList), DebugFishingMenuList, &FishingDebugListWindowData, NULL);
	}
}

//釣り用ウィンドウ構築
static void SetFishingRodWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);
	d_work->rod = 0;
	//メイン処理タスク追加
	pTcb = TCB_Add(RodDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//ロッド表示
	DrawFishingRod(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}
//釣り竿指定ウィンドウセット
static void SetupFishingRod(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetFishingRodWindow(fsys);
}

//釣り確率フラグ表示
static void DrawFishingProb(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, DebugFishProbFlg, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

//確率フラグ表示中タスク
static void FishProbDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if ( (sys.trg & PAD_KEY_UP) ||
			(sys.trg & PAD_KEY_DOWN)){
		DebugFishProbFlg = (DebugFishProbFlg+1)%2;
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawFishingProb(d_work);
	}

	if ( (sys.trg & PAD_BUTTON_A) ||
			(sys.trg & PAD_BUTTON_B) ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugFishingMenuList), DebugFishingMenuList, &FishingDebugListWindowData, NULL);
	}
}

//釣り用ウィンドウ構築
static void SetFishingProbWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(FishProbDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//確率フラグ表示
	DrawFishingProb(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//釣り確率フラグ指定ウィンドウセット
static void SetupFishingProb(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetFishingProbWindow(fsys);
}
#endif

/////////////////////////////////////////////////////////////////////////////////////////
//移動ポケモン
static void SetMovePokeInfoWindow(struct _FIELDSYS_WORK * fsys);
static void DrawMovePokeInfo(DEBUG_WORK_DATA *d_work);
static void MovePokeInfoDispTask(TCB_PTR tcb,void* work);

static void SetEntryMovePokeWindow(struct _FIELDSYS_WORK * fsys);
static void DrawMovePokeName(DEBUG_WORK_DATA *d_work);
static void EntryMovePokeTask(TCB_PTR tcb,void* work);

static void SetMovePokeZoneChgWin(struct _FIELDSYS_WORK * fsys, const u16 inPos);
static void DrawMovePokeZone(DEBUG_WORK_DATA *d_work);
static void MovePokeZoneDispTask(TCB_PTR tcb,void* work);

//メイン
static void DebugWinMovePoke(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugMovePokeMenuList), DebugMovePokeMenuList, &MovePokeDebugListWindowData, NULL);
}

//情報表示ウィンドウセット
static void SetupMovePokeInfo(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetMovePokeInfoWindow(fsys);
}

//移動ポケモン情報ウィンドウ構築
static void SetMovePokeInfoWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(32, HEAPID_D_SAITO);
	d_work->rod = 0;
	d_work->MovePokeInfoNo = 0;
	//メイン処理タスク追加
	pTcb = TCB_Add(MovePokeInfoDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 16, 18, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//情報表示
	DrawMovePokeInfo(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//移動ポケモン情報表示
static void DrawMovePokeInfo(DEBUG_WORK_DATA *d_work)
{
	STRBUF *str;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;
	MPD_PTR mpd;
	ENC_SV_PTR data;

	int poke_name_list[MOVE_POKE_MAX] = {	D_SAITO_MP_RAI,
											D_SAITO_MP_EN,
											D_SAITO_MP_ASU,
											D_SAITO_MP_OSU};

	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	str = d_work->StrBuf;
	msg_buf = d_work->StrBuf;

	//セーブデータ取得
	data = EncDataSave_GetSaveDataPtr(d_work->fsys->savedata);
	mpd = EncDataSave_GetMovePokeDataPtr(data, d_work->MovePokeInfoNo);


	{
		int zone_id = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_ZONE_ID);
		int monsno = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_MONSNO);
		u32 pow_rnd = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_POW_RND);
		u32 per_rnd = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_PER_RND);
		u8 hp = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_HP);
		u8 lv = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_LV);
		u8 cond = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_COND);
		u8 enc = EncDataSave_GetMovePokeDataParam(mpd, MP_PARAM_ENC);

		//ポケモン名
		MSGMAN_GetString(man, poke_name_list[d_work->MovePokeInfoNo] ,msg_buf);
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );
		//モンスターナンバー
		STRBUF_SetNumber(str, monsno, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 1*16, MSG_ALLPUT, NULL );
		//レベル
		STRBUF_SetNumber(str, lv, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 2*16, MSG_ALLPUT, NULL );
		//HP
		STRBUF_SetNumber(str, hp, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 3*16, MSG_ALLPUT, NULL );
		//パワー乱数
		STRBUF_SetHexNumber(str, pow_rnd, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 4*16, MSG_ALLPUT, NULL );
		//個性乱数
		STRBUF_SetHexNumber(str, per_rnd, 8, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 5*16, MSG_ALLPUT, NULL );
		//状態
		STRBUF_SetNumber(str, cond, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 6*16, MSG_ALLPUT, NULL );
		//場所
		STRBUF_SetNumber(str, zone_id, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 7*16, MSG_ALLPUT, NULL );
		PNC_GetPlaceNameFromZoneID(zone_id, HEAPID_FIELD, msg_buf);
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, msg_buf, 4*8, 7*16, MSG_ALLPUT, NULL );
		//エンカウントフラグ
		STRBUF_SetNumber(str, enc, 2, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, str, 1*8, 8*16, MSG_ALLPUT, NULL );

		OS_Printf("pow=%u\n",pow_rnd);
		OS_Printf("per=%u\n",per_rnd);
	}

	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &d_work->win );
}

//移動ポケモン情報表示タスク
static void MovePokeInfoDispTask(TCB_PTR tcb,void* work)
{
	BOOL flg;
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	flg = FALSE;
	if ( sys.trg & PAD_KEY_RIGHT ){
		flg = TRUE;
		if (d_work->MovePokeInfoNo == MOVE_POKE_MAX-1){
			d_work->MovePokeInfoNo = 0;
		}else{
			d_work->MovePokeInfoNo++;
		}
	}else if (sys.trg & PAD_KEY_LEFT){
		flg = TRUE;
		if (d_work->MovePokeInfoNo == 0){
			d_work->MovePokeInfoNo = MOVE_POKE_MAX-1;
		}else{
			d_work->MovePokeInfoNo--;
		}
	}

	if (flg == TRUE){
		//移動ポケモン情報表示
		DrawMovePokeInfo(d_work);
	}

	if (sys.trg & PAD_BUTTON_B){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//移動ポケモンメニューメインへ
		MakeBmpList(fsys, NELEMS(DebugMovePokeMenuList), DebugMovePokeMenuList, &MovePokeDebugListWindowData, NULL);
	}
}

static void SetupEntryMovePoke(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetEntryMovePokeWindow(fsys);
}

//移動ポケモンエントリウィンドウ構築
static void SetEntryMovePokeWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(16, HEAPID_D_SAITO); //移動ポケモン名を表示
	d_work->rod = 0;
	d_work->MovePokeInfoNo = 0;
	//メイン処理タスク追加
	pTcb = TCB_Add(EntryMovePokeTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 6, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//情報表示
	DrawMovePokeName(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//移動ポケモン名表示
static void DrawMovePokeName(DEBUG_WORK_DATA *d_work)
{
	MSGDATA_MANAGER* man;

	int poke_name_list[MOVE_POKE_MAX] = {	D_SAITO_MP_RAI,
											D_SAITO_MP_EN,
											D_SAITO_MP_ASU,
											D_SAITO_MP_OSU };

	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);

	//ポケモン名
	MSGMAN_GetString(man, poke_name_list[d_work->MovePokeInfoNo] ,d_work->StrBuf);
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 1*8, 0, MSG_ALLPUT, NULL );

	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &d_work->win );
}

//エントリ移動ポケモン選択タスク
static void EntryMovePokeTask(TCB_PTR tcb,void* work)
{
	BOOL flg;
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	flg = FALSE;
	if ( sys.trg & PAD_KEY_RIGHT ){
		flg = TRUE;
		if (d_work->MovePokeInfoNo == MOVE_POKE_MAX-1){
			d_work->MovePokeInfoNo = 0;
		}else{
			d_work->MovePokeInfoNo++;
		}
	}else if (sys.trg & PAD_KEY_LEFT){
		flg = TRUE;
		if (d_work->MovePokeInfoNo == 0){
			d_work->MovePokeInfoNo = MOVE_POKE_MAX-1;
		}else{
			d_work->MovePokeInfoNo--;
		}
	}

	if (flg == TRUE){
		//移動ポケモン情報表示
		DrawMovePokeName(d_work);
	}

	if (sys.trg & PAD_BUTTON_A){
		//エントリ
		MP_AddMovePoke(d_work->fsys->savedata, d_work->MovePokeInfoNo);
		Snd_SePlay( SEQ_SE_DP_SELECT );		//登録したら鳴らしとく

	}else if (sys.trg & PAD_BUTTON_B){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//移動ポケモンメニューメインへ
		MakeBmpList(fsys, NELEMS(DebugMovePokeMenuList), DebugMovePokeMenuList, &MovePokeDebugListWindowData, NULL);
	}
}

//移動ポケモン名メイン
static void DebugWinMovePokeName(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugMovePokeNameList), DebugMovePokeNameList, &MovePokeNameDebugListWindowData, NULL);
}

//ゾーン変更ウィンドウセット
static void SetupMovePokeZoneChgWin(TCB_PTR tcb,void *work)
{
	u16 pos;
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す(ワークは残す)
	FreeDebugWindowNoFreeMem(tcb,work);
	pos = wp->debug_cursor;
	//ワークメモリ開放
	sys_FreeMemoryEz(work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetMovePokeZoneChgWin(fsys,pos);
}

//移動ポケモンゾーンウィンドウ構築
static void SetMovePokeZoneChgWin(struct _FIELDSYS_WORK * fsys, const u16 inPos)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->MovePokeInfoNo = inPos;
	{
		ENC_SV_PTR data = EncDataSave_GetSaveDataPtr(fsys->savedata);
		if ( EncDataSave_IsMovePokeValid(data, d_work->MovePokeInfoNo) ){
			d_work->zone_idx = EncDataSave_GetMovePokeZoneIdx(data, d_work->MovePokeInfoNo);
		}else{
			d_work->zone_idx = LOCATION_MAX;
		}
	}
	d_work->StrBuf = STRBUF_Create(32, HEAPID_D_SAITO); //ゾーン名を表示
	//メイン処理タスク追加
	pTcb = TCB_Add(MovePokeZoneDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 18, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//情報表示
	DrawMovePokeZone(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//移動ポケモンゾーン表示
static void DrawMovePokeZone(DEBUG_WORK_DATA *d_work)
{
	int zone_id;
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );

	//ゾーン名取得
	if ((d_work->zone_idx>=0)&&(d_work->zone_idx<LOCATION_MAX)){
		zone_id = MP_GetMovePokeZone(d_work->zone_idx);
	}else{
		zone_id = 0;
	}
	PNC_GetPlaceNameFromZoneID(zone_id, HEAPID_FIELD, d_work->StrBuf);
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

//移動ポケモンゾーン表示中タスク
static void MovePokeZoneDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if (sys.repeat & PAD_KEY_UP){
		d_work->zone_idx++;
		if (d_work->zone_idx>=LOCATION_MAX){
			d_work->zone_idx = 0;
		}
	}else if(sys.repeat & PAD_KEY_DOWN){
		d_work->zone_idx--;
		if (d_work->zone_idx<0){
			d_work->zone_idx = LOCATION_MAX-1;
		}
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawMovePokeZone(d_work);
	}

	if ( sys.trg & PAD_BUTTON_A ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		Snd_SePlay( SEQ_SE_DP_SELECT );		//場所変更したら鳴らしとく
		//場所変更
		MP_DebugUpdateData( EncDataSave_GetSaveDataPtr(fsys->savedata),
							d_work->MovePokeInfoNo, d_work->zone_idx);

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		//タスク消去
		TCB_Delete(tcb);
		sys_FreeMemoryEz((void *)work);
		//移動ポケモンメニューメインへ
		MakeBmpList(fsys, NELEMS(DebugMovePokeMenuList), DebugMovePokeMenuList, &MovePokeDebugListWindowData, NULL);
	}else if(sys.trg & PAD_BUTTON_B){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		//タスク消去
		TCB_Delete(tcb);
		sys_FreeMemoryEz((void *)work);
		//移動ポケモンメニューメインへ
		MakeBmpList(fsys, NELEMS(DebugMovePokeMenuList), DebugMovePokeMenuList, &MovePokeDebugListWindowData, NULL);
	}
}

//////////////////////////////////////////////////////////////////////////////
static void SetGeneZoneInfoWin(struct _FIELDSYS_WORK * fsys);
static void DrawGeneZone(DEBUG_WORK_DATA *d_work);
static void GeneInfoDispTask(TCB_PTR tcb,void* work);
//大量発生
static void DebugGenerate(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugGeneMenuList), DebugGeneMenuList, &GeneDebugListWindowData, NULL);
}

//大量発生情報表示セットアップ
static void SetupGeneZoneInfoWin(TCB_PTR tcb,void *work)
{
	u16 pos;
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetGeneZoneInfoWin(fsys);
}

//大量発生開始
static void DebugStartGenerate(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
	//大量発生開始
	EncDataSave_StartGenerate( fsys->savedata );
	Snd_SePlay( SEQ_SE_DP_SELECT );		//発生させたら鳴らしとく
}

//大量発生情報表示セットアップ
static void SetGeneZoneInfoWin(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(32, HEAPID_D_SAITO); //ゾーン名を表示
	//メイン処理タスク追加
	pTcb = TCB_Add(GeneInfoDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 18, 4, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//情報表示
	DrawGeneZone(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//大量発生場所表示
static void DrawGeneZone(DEBUG_WORK_DATA *d_work)
{
	ENC_SV_PTR data;
	MSGDATA_MANAGER* man;

	u16 zone_id;
	u16 monsno;
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);

	data = EncDataSave_GetSaveDataPtr(d_work->fsys->savedata);

	//ゾーン名取得
	GenerateZone_GetInfo(EncDataSave_GetRandSeed(data,  ENC_RND_SEED_GENERATE), &zone_id, &monsno);
	PNC_GetPlaceNameFromZoneID(zone_id, HEAPID_FIELD, d_work->StrBuf);
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
	if(EncDataSave_IsGenerate( data )){
		MSGMAN_GetString(man, D_SAITO_GENE_ON ,d_work->StrBuf);
	}else{
		MSGMAN_GetString(man, D_SAITO_GENE_OFF ,d_work->StrBuf);
	}
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 16, MSG_ALLPUT, NULL );
	MSGMAN_Delete( man );
}

//発生場所表示中タスク
static void GeneInfoDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	if (sys.trg & PAD_BUTTON_B){

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//大量発生メイン
		MakeBmpList(d_work->fsys, NELEMS(DebugGeneMenuList), DebugGeneMenuList, &GeneDebugListWindowData, NULL);
	}
}

////////////////////////////////////////////////////////////////////
static void DebugSafari(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	DebugWindowExit(tcb,work);
}

//AGB
#if 0
static void DebugSetAgbVer(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugAgbMenuList), DebugAgbMenuList, &AgbDebugListWindowData, NULL);
}

//ＡＧＢスロットバージョン変更
static void DebugAgbVer(TCB_PTR tcb,void *work)
{
	DEBUG_WINDOW_DATA *wp;
	//メインウィンドウを消す(ワークは残す)
	FreeDebugWindowNoFreeMem(tcb,work);

	wp = (DEBUG_WINDOW_DATA *)work;

	switch(wp->debug_cursor){
	case 0:
		sys.AgbCasetteVersion = 0;
		break;
	case 1:
		sys.AgbCasetteVersion = VERSION_SAPPHIRE;
		break;
	case 2:
		sys.AgbCasetteVersion = VERSION_RUBY;
		break;
	case 3:
		sys.AgbCasetteVersion = VERSION_EMERALD;
		break;
	case 4:
		sys.AgbCasetteVersion = VERSION_RED;
		break;
	case 5:
		sys.AgbCasetteVersion = VERSION_GREEN;
		break;
	}

	OS_Printf("ver:%d\n",sys.AgbCasetteVersion);

	Snd_SePlay( SEQ_SE_DP_SELECT );		//発生させたら鳴らしとく

	//ワークメモリ開放
	sys_FreeMemoryEz(work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
}
#endif
//-----------------------------------------------------------------------
//
//ポケモン吹き出し

extern int debug_ballon_type;
//アニメナンバー表示
static void DrawBallonNum(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, debug_ballon_type, 3, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

//ポケモン吹き出し表示中タスク
static void BallonTypeDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if (sys.repeat & PAD_KEY_UP){
		debug_ballon_type++;
		if( debug_ballon_type > 14 ){
			debug_ballon_type = 0;
		}
	}else if(sys.repeat & PAD_KEY_DOWN){
		debug_ballon_type--;
		if( debug_ballon_type < 0 ){
			debug_ballon_type = 14;
		}
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawBallonNum(d_work);
	}

	if ((sys.trg & PAD_BUTTON_B)||(sys.trg & PAD_BUTTON_A)){

		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

//吹き出し用ウィンドウ構築
static void SetBallonTypeWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(10, HEAPID_D_SAITO);
	//メイン処理タスク追加
	pTcb = TCB_Add(BallonTypeDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 4, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//チェーン表示
	DrawBallonNum(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//吹き出し指定ウィンドウセット
static void SetupBallonTypeNum(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetBallonTypeWindow(fsys);
}


///////////////////////////////////////////////
//ポケスロン
extern DEBUG_PKTHLN_WORK DebugPkthlnWk;

static void DebugSub_InitPokethlon(void *work)
{
	POKETHLON_HEADER *header;
	DBG_SAI_ST_PTR st_ptr = work;
	struct _FIELDSYS_WORK * fsys = DebugSaitoSt_GetFieldSysPtr(st_ptr);
///	wp->subWork = FieldPorutoCase_InitCall(wp->fsys,HEAPID_BASE_DEBUG);
	//ヘッダー情報作成（とりあえず、直に編集）
	{
		header = sys_AllocMemory(HEAPID_BASE_DEBUG,sizeof(POKETHLON_HEADER));
		header->GameType = PKTHLN_GAME_ALONE;
		header->SaveData = GameSystem_GetSaveData(fsys);
		header->CourseID = CRS_ID_MAS;
		header->AllStar = 1;
#ifdef PM_DEBUG
	#ifdef DEBUG_PKTH_EVT_HOOK
		// デフォルトの種目をフック
		if (!DebugPkthlnWk.Flg){
			DebugPkthlnWk.Evt[0] = DEBUG_HOOK_EVT_CODE;
			DebugPkthlnWk.Evt[1] = DEBUG_HOOK_EVT_CODE;
			DebugPkthlnWk.Evt[2] = DEBUG_HOOK_EVT_CODE;
			DebugPkthlnWk.Evt[3] = DEBUG_HOOK_EVT_CODE;
			DebugPkthlnWk.Crs = CRS_ID_MAS;
			DebugPkthlnWk.Flg = 1;
		}
	#endif
		if (DebugPkthlnWk.Flg){
			header->CourseID = DebugPkthlnWk.Crs;
		}
#endif
	}

	DebugSaitoSt_SetWork(st_ptr, header);
	Pokethlon_SetProc(fsys, header);
	//BGM保存
	SaveBGMNo(st_ptr);
}

//ポケスロン呼び出し
static void CallPokethlon(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//ポケスロン用ＴＢＣ作成
	st_ptr = DebugSaitoSt_AllocWork(fsys, HEAPID_BASE_DEBUG);
	DebugSaitoSt_SetFunc(st_ptr, DebugSub_InitPokethlon);
	TCB_Add(DebugSaitoSt_FuncCall, st_ptr, 0);
}

//ポケスロンメニュー(開始、フラグ操作、競技選択)
static void DebugWinPokethlon(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
}

//ポケスロンデバッグフラグ指定ウィンドウセット
static void SetupPkthlnDFlag(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetPkthlnDFlagWindow(fsys);
}

//ポケスロンデバッグフラグ用ウィンドウ構築
static void SetPkthlnDFlagWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(PkthlnDFlagDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//確率フラグ表示
	DrawPkthlnDFlag(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//ポケスロンデバッグフラグ表示中タスク
static void PkthlnDFlagDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if ( (sys.trg & PAD_KEY_UP) ||
			(sys.trg & PAD_KEY_DOWN)){
		DebugPkthlnWk.Flg = (DebugPkthlnWk.Flg+1)%2;
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawPkthlnDFlag(d_work);
	}

	if ( (sys.trg & PAD_BUTTON_A) ||
			(sys.trg & PAD_BUTTON_B) ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//ポケスロンデバッグフラグ表示
static void DrawPkthlnDFlag(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, DebugPkthlnWk.Flg, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

//ポケスロン競技ウィンドウ構築
static void SetupPkthlnEvtWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetPkthlnEvtWindow(fsys);
}

//ポケスロンコースウィンドウ構築
static void SetupPkthlnCrsWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetPkthlnCrsWindow(fsys);
}

//ポケスロン競技用ウィンドウ構築
static void SetPkthlnEvtWindow(struct _FIELDSYS_WORK * fsys)
{

	D_PKTH_WORK *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(D_PKTH_WORK));
	wk->fsys = fsys;
	wk->cursor = BMPCURSOR_Create( HEAPID_BASE_APP );
	wk->CurPoint = 0;
	//メイン処理タスク追加
	pTcb = TCB_Add(PkthlnEvtDispTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 9, 10, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//競技表示
	DrawPkthlnEvt(wk);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//ポケスロンコース用ウィンドウ構築
static void SetPkthlnCrsWindow(struct _FIELDSYS_WORK * fsys)
{

	D_PKTH_WORK *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(D_PKTH_WORK));
	wk->fsys = fsys;
	//メイン処理タスク追加
	pTcb = TCB_Add(PkthlnCrsDispTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 9, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//コース表示
	DrawPkthlnCrs(wk);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//スロンポイントウィンドウ構築
static void SetupPkthlnPointWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetPkthlnPointWindow(fsys);
}

//スロンポイント用ウィンドウ構築
static void SetPkthlnPointWindow(struct _FIELDSYS_WORK * fsys)
{

	D_PKTH_WORK *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(D_PKTH_WORK));
	wk->fsys = fsys;
	//メイン処理タスク追加
	pTcb = TCB_Add(PkthlnPointDispTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 9, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//スロンポイント表示
	DrawPkthlnPoint(wk);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//ポケスロン競技ウィンドウ表示中タスク
static void PkthlnEvtDispTask(TCB_PTR tcb,void* work)
{
	u8 evt_no;
	BOOL end;
	BOOL redraw;
	D_PKTH_WORK *wk = (D_PKTH_WORK *)work;

	end = FALSE;
	redraw = FALSE;

	if (sys.trg & PAD_KEY_UP){
		if (wk->CurPoint == 0){
			wk->CurPoint = DEBUG_PKTH_EVT_LOOP_NUM-1;
		}else{
			wk->CurPoint--;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_KEY_DOWN){
		if (wk->CurPoint == DEBUG_PKTH_EVT_LOOP_NUM-1){
			wk->CurPoint = 0;
		}else{
			wk->CurPoint++;
		}
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_RIGHT){
		evt_no = DebugPkthlnWk.Evt[wk->CurPoint];
		if (evt_no == DEBUG_PKTH_EVT_NUM-1 ){
			evt_no = 0;
		}else{
			evt_no++;
		}
		DebugPkthlnWk.Evt[wk->CurPoint] = evt_no;
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_LEFT){
		evt_no = DebugPkthlnWk.Evt[wk->CurPoint];
		if (evt_no == 0){
			evt_no = DEBUG_PKTH_EVT_NUM-1;
		}else{
			evt_no--;
		}
		DebugPkthlnWk.Evt[wk->CurPoint] = evt_no;
		redraw = TRUE;
	}else if ( (sys.trg & PAD_BUTTON_B)||(sys.trg & PAD_BUTTON_A) ){
		end = TRUE;
	}

	if (redraw){
		DrawPkthlnEvt(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;
		//カーソル削除
		BMPCURSOR_Delete( wk->cursor );

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//ポケスロンコースウィンドウ表示中タスク
static void PkthlnCrsDispTask(TCB_PTR tcb,void* work)
{
	u8 crs_no;
	BOOL end;
	BOOL redraw;
	D_PKTH_WORK *wk = (D_PKTH_WORK *)work;

	end = FALSE;
	redraw = FALSE;

	if (sys.trg & PAD_KEY_RIGHT){
		crs_no = DebugPkthlnWk.Crs;
		if (crs_no == DEBUG_PKTH_CRS_NUM-1 ){
			crs_no = 0;
		}else{
			crs_no++;
		}
		DebugPkthlnWk.Crs = crs_no;
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_LEFT){
		crs_no = DebugPkthlnWk.Crs;
		if (crs_no == 0){
			crs_no = DEBUG_PKTH_CRS_NUM-1;
		}else{
			crs_no--;
		}
		DebugPkthlnWk.Crs = crs_no;
		redraw = TRUE;
	}else if ( (sys.trg & PAD_BUTTON_B)||(sys.trg & PAD_BUTTON_A) ){
		end = TRUE;
	}

	if (redraw){
		DrawPkthlnCrs(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//スロンポイントウィンドウ表示中タスク
static void PkthlnPointDispTask(TCB_PTR tcb,void* work)
{
	u8 crs_no;
	BOOL end;
	BOOL redraw;
	PKTHLN_SV_DATA_PTR ptr;
	D_PKTH_WORK *wk = (D_PKTH_WORK *)work;

	end = FALSE;
	redraw = FALSE;

	ptr = PkthlnSv_GetSaveData(wk->fsys->savedata);

	if (sys.trg & PAD_KEY_RIGHT){
		PkthlnSv_AddThlnPoint(ptr, 1 );
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_LEFT){
		PkthlnSv_SubThlnPoint(ptr, 1 );
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_UP){
		PkthlnSv_AddThlnPoint(ptr, 10 );
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_LEFT){
		PkthlnSv_SubThlnPoint(ptr, 10 );
		redraw = TRUE;
	}else if (sys.trg & PAD_BUTTON_R){
		PkthlnSv_AddThlnPoint(ptr, 100 );
		redraw = TRUE;
	}else if (sys.trg & PAD_BUTTON_L){
		PkthlnSv_SubThlnPoint(ptr, 100 );
		redraw = TRUE;
	}else if ( (sys.trg & PAD_BUTTON_B)||(sys.trg & PAD_BUTTON_A) ){
		end = TRUE;
	}else if (sys.cont & PAD_BUTTON_R){
		//ベタ押し時間カウント
		if ( wk->ContTime < DEBUG_CONT_TIME ){
			wk->ContTime++;
		}else{
			PkthlnSv_AddThlnPoint(ptr, 100 );
			redraw = TRUE;
		}
	}else if(sys.cont & PAD_BUTTON_L){
		//ベタ押し時間カウント
		if ( wk->ContTime < DEBUG_CONT_TIME ){
			wk->ContTime++;
		}else{
			PkthlnSv_SubThlnPoint(ptr, 100 );
			redraw = TRUE;
		}
	}else{	//ボタン押してないので、内部情報をクリア
		wk->ContTime = 0;
	}

	if (redraw){
		DrawPkthlnPoint(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//競技表示
static void DrawPkthlnEvt(D_PKTH_WORK *wk)
{
	int i;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	BMPCURSOR_Print( wk->cursor, &wk->win, 0, wk->CurPoint*16 );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(16,HEAPID_D_SAITO);

	for (i=0;i<DEBUG_PKTH_EVT_LOOP_NUM;i++){
		MSGMAN_GetString(man, D_SAITO_PKTHLN_EVT01+DebugPkthlnWk.Evt[i] ,msg_buf);
		GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, i*16, MSG_ALLPUT, NULL );
	}

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}

//コース表示
static void DrawPkthlnCrs(D_PKTH_WORK *wk)
{
	int i;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_pokethlon_info_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(40,HEAPID_D_SAITO);

	MSGMAN_GetString(man, DebugPkthlnWk.Crs ,msg_buf);
	GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}

//スロンポイント表示
static void DrawPkthlnPoint(D_PKTH_WORK *wk)
{
	int i;
	int point;

	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;
	PKTHLN_SV_DATA_PTR ptr;
	ptr = PkthlnSv_GetSaveData(wk->fsys->savedata);

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_pokethlon_info_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(40,HEAPID_D_SAITO);

	point = PkthlnSv_GetThlnPoint ( ptr );

	STRBUF_SetNumber( msg_buf, point, 5, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}


//メダルウィンドウ構築
static void SetupMedalWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetMedalWindow(fsys);
}

//メダル用ウィンドウ構築
static void SetMedalWindow(struct _FIELDSYS_WORK * fsys)
{
	D_PKTH_WORK *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(D_PKTH_WORK));
	wk->fsys = fsys;
	wk->cursor = BMPCURSOR_Create( HEAPID_BASE_APP );
	wk->CurPoint = 0;

	wk->MedalMonsNo = 1;

	//メイン処理タスク追加
	pTcb = TCB_Add(MedalDispTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 5, 12, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//メダル表示
	DrawMedal(wk);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//メダルウィンドウ表示中タスク
static void MedalDispTask(TCB_PTR tcb,void* work)
{
	PKTHLN_SV_DATA_PTR ptr;
	BOOL end;
	BOOL redraw;
	D_PKTH_WORK *wk = (D_PKTH_WORK *)work;

	end = FALSE;
	redraw = FALSE;

	if (sys.trg & PAD_KEY_UP){
		if (wk->CurPoint == 0){
			wk->CurPoint = DEBUG_MEDAL_LOOP_NUM-1;
		}else{
			wk->CurPoint--;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_KEY_DOWN){
		if (wk->CurPoint == DEBUG_MEDAL_LOOP_NUM-1){
			wk->CurPoint = 0;
		}else{
			wk->CurPoint++;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_KEY_RIGHT){
		if (wk->CurPoint == 0){
			wk->MedalMonsNo++;
			if (wk->MedalMonsNo > MONSNO_END){
				wk->MedalMonsNo = 1;
			}
			redraw = TRUE;
		}
	}else if(sys.trg & PAD_KEY_LEFT){
		if (wk->CurPoint == 0){
			wk->MedalMonsNo--;
			if (wk->MedalMonsNo <= 0){
				wk->MedalMonsNo = MONSNO_AUSU;
			}
			redraw = TRUE;
		}
	}else if(sys.cont & PAD_KEY_RIGHT){
		if (wk->CurPoint == 0){
			if (wk->ContTime < DEBUG_CONT_TIME){
				wk->ContTime++;
			}else{
				wk->MedalMonsNo++;
				if (wk->MedalMonsNo > MONSNO_END){
					wk->MedalMonsNo = 1;
				}
				redraw = TRUE;
			}
		}
	}else if(sys.cont & PAD_KEY_LEFT){
		if (wk->CurPoint == 0){
			if (wk->ContTime < DEBUG_CONT_TIME){
				wk->ContTime++;
			}else{
				wk->MedalMonsNo--;
				if (wk->MedalMonsNo <= 0){
					wk->MedalMonsNo = MONSNO_AUSU;
				}
				redraw = TRUE;
			}
		}
	}else if ( sys.trg & PAD_BUTTON_A ){
		//カーソル位置が一番上の場合は、メダルセットしない
		if (wk->CurPoint != 0){
			u8 crs_id;
			crs_id = wk->CurPoint-1;
			//メダルセット
			ptr = PkthlnSv_GetSaveData(wk->fsys->savedata);
			PkthlnSv_SetMedalData(ptr, crs_id, wk->MedalMonsNo);
			redraw = TRUE;
		}
	}else if ( sys.trg & PAD_BUTTON_B ){
		end = TRUE;
	}else{
		wk->ContTime = 0;
	}


	if (redraw){
		DrawMedal(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;

		//カーソル削除
		BMPCURSOR_Delete( wk->cursor );

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);

		//ウィンドウ構築
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);

	}
}

static void DrawMedal(D_PKTH_WORK *wk)
{
	int i;
	PKTHLN_SV_DATA_PTR ptr;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	ptr = PkthlnSv_GetSaveData(wk->fsys->savedata);

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	BMPCURSOR_Print( wk->cursor, &wk->win, 0, wk->CurPoint*16 );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(16,HEAPID_D_SAITO);

	STRBUF_SetNumber( msg_buf, wk->MedalMonsNo, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );

	for (i=0;i<DEBUG_MEDAL_NUM;i++){
		int msg;
		u8 crs_id;
		if (PkthlnSv_IsMedal(ptr, i, wk->MedalMonsNo)){
			msg = D_SAITO_LEAF_OK;
		}else{
			msg = D_SAITO_LEAF_NG;
		}
		MSGMAN_GetString(man, msg ,msg_buf);
		GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 16+i*16, MSG_ALLPUT, NULL );
	}

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}
//////////////////////////////////////////////////


//スペックウィンドウ構築
static void SetupSpecWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetSpecWindow(fsys);
}

//スペック用ウィンドウ構築
static void SetSpecWindow(struct _FIELDSYS_WORK * fsys)
{
	D_PKTH_WORK *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(D_PKTH_WORK));
	wk->fsys = fsys;
	wk->cursor = BMPCURSOR_Create( HEAPID_BASE_APP );
	wk->CurPoint = 0;
	wk->ThlnEntryIdx = 0;

	//メイン処理タスク追加
	pTcb = TCB_Add(SpecDispTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 10, 12, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//スペック表示
	DrawSpec(wk);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//スペックウィンドウ表示中タスク
static void SpecDispTask(TCB_PTR tcb,void* work)
{
	BOOL end;
	BOOL redraw;
	D_PKTH_WORK *wk = (D_PKTH_WORK *)work;

	end = FALSE;
	redraw = FALSE;

	if (sys.trg & PAD_KEY_UP){
		if (wk->CurPoint == 0){
			wk->CurPoint = DEBUG_MEDAL_LOOP_NUM-1;
		}else{
			wk->CurPoint--;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_KEY_DOWN){
		if (wk->CurPoint == DEBUG_MEDAL_LOOP_NUM-1){
			wk->CurPoint = 0;
		}else{
			wk->CurPoint++;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_KEY_LEFT){
		if (DebugPkthlnWk.Spec[wk->ThlnEntryIdx][wk->CurPoint] > 0 ){
			//スペックさげる
			DebugPkthlnWk.Spec[wk->ThlnEntryIdx][wk->CurPoint]--;
			redraw = TRUE;
		}
	}else if(sys.trg & PAD_KEY_RIGHT){
		if (DebugPkthlnWk.Spec[wk->ThlnEntryIdx][wk->CurPoint] < DEBUG_SPEC_MAX ){
			//スペックあげる
			DebugPkthlnWk.Spec[wk->ThlnEntryIdx][wk->CurPoint]++;
			redraw = TRUE;
		}
	}else if(sys.trg & PAD_BUTTON_R){
		wk->ThlnEntryIdx++;
		if (wk->ThlnEntryIdx>=3){
			wk->ThlnEntryIdx = 0;
		}
		redraw = TRUE;
	}else if(sys.trg & PAD_BUTTON_L){
		wk->ThlnEntryIdx--;
		if (wk->ThlnEntryIdx < 0){
			wk->ThlnEntryIdx = 2;
		}
		redraw = TRUE;
	}else if ( (sys.trg & PAD_BUTTON_A)||(sys.trg & PAD_BUTTON_B) ){
		end = TRUE;
	}


	if (redraw){
		DrawSpec(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;

		//カーソル削除
		BMPCURSOR_Delete( wk->cursor );

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);

		//ウィンドウ構築
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);

	}
}

static void DrawSpec(D_PKTH_WORK *wk)
{
	int i;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	const int msg[5] = {
		D_SAITO_PKTHLN_SPEC_POW,
		D_SAITO_PKTHLN_SPEC_SPD,
		D_SAITO_PKTHLN_SPEC_JMP,
		D_SAITO_PKTHLN_SPEC_STA,
		D_SAITO_PKTHLN_SPEC_TEQ
	};

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	BMPCURSOR_Print( wk->cursor, &wk->win, 0, 16+wk->CurPoint*16 );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(16,HEAPID_D_SAITO);

	STRBUF_SetNumber( msg_buf, wk->ThlnEntryIdx, 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );

	for (i=0;i<DEBUG_SPEC_LOOP_NUM;i++){
		MSGMAN_GetString(man, msg[i] ,msg_buf);
		GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 16+i*16, MSG_ALLPUT, NULL );
		STRBUF_SetNumber( msg_buf, DebugPkthlnWk.Spec[wk->ThlnEntryIdx][i], 1, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
		GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, (1*8)+24, 16+i*16, MSG_ALLPUT, NULL );
	}

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}


///////////////////////////////////////////////
//スペックデバッグフラグ指定ウィンドウセット
static void SetupSpecDFlag(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetSpecDFlagWindow(fsys);
}

//スペックデバッグフラグ用ウィンドウ構築
static void SetSpecDFlagWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(SpecDFlagDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//フラグ表示
	DrawSpecDFlag(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//スペックデバッグフラグ表示中タスク
static void SpecDFlagDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if ( (sys.trg & PAD_KEY_UP) ||
			(sys.trg & PAD_KEY_DOWN)){
		DebugPkthlnWk.SpecFlg = (DebugPkthlnWk.SpecFlg+1)%2;
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawSpecDFlag(d_work);
	}

	if ( (sys.trg & PAD_BUTTON_A) ||
			(sys.trg & PAD_BUTTON_B) ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//スペックデバッグフラグ表示
static void DrawSpecDFlag(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, DebugPkthlnWk.SpecFlg, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

///////////////////////////////////////////////

//競技時間無限フラグ指定ウィンドウセット
static void SetupInfinityFlg(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetInfinityFlgWindow(fsys);
}

//競技時間無限フラグ用ウィンドウ構築
static void SetInfinityFlgWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(InfinityFlgDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//フラグ表示
	DrawInfinityFlg(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//競技時間無限フラグ表示中タスク
static void InfinityFlgDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if ( (sys.trg & PAD_KEY_UP) ||
			(sys.trg & PAD_KEY_DOWN)){
		DebugPkthlnWk.TimeInfinity = (DebugPkthlnWk.TimeInfinity+1)%2;
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawInfinityFlg(d_work);
	}

	if ( (sys.trg & PAD_BUTTON_A) ||
			(sys.trg & PAD_BUTTON_B) ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//競技時間無限フラグ表示
static void DrawInfinityFlg(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, DebugPkthlnWk.TimeInfinity, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

///////////////////////////////////////////////

//AI停止フラグ指定ウィンドウセット
static void SetupEneStopFlg(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//ウィンドウ構築
	SetEneStopFlgWindow(fsys);
}

//AI停止フラグ用ウィンドウ構築
static void SetEneStopFlgWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *d_work = NULL;
	TCB_PTR	pTcb = NULL;
	d_work = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	d_work->fsys = fsys;
	d_work->StrBuf = STRBUF_Create(2, HEAPID_D_SAITO);

	//メイン処理タスク追加
	pTcb = TCB_Add(EneStopFlgDispTask,d_work,0);

	GF_BGL_BmpWinAdd( d_work->fsys->bgl,&d_work->win,GF_BGL_FRAME3_M, 0, 0, 2, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );

	//フラグ表示
	DrawEneStopFlg(d_work);

	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//AI停止フラグ表示中タスク
static void EneStopFlgDispTask(TCB_PTR tcb,void* work)
{
	DEBUG_WORK_DATA *d_work = (DEBUG_WORK_DATA *)work;

	BOOL draw;

	draw = TRUE;
	if ( (sys.trg & PAD_KEY_UP) ||
			(sys.trg & PAD_KEY_DOWN)){
		DebugPkthlnWk.AI_Stop = (DebugPkthlnWk.AI_Stop+1)%2;
	}else{
		draw = FALSE;
	}

	if (draw){
		DrawEneStopFlg(d_work);
	}

	if ( (sys.trg & PAD_BUTTON_A) ||
			(sys.trg & PAD_BUTTON_B) ){
		struct _FIELDSYS_WORK * fsys;
		fsys = d_work->fsys;
		GF_BGL_BmpWinOff( &d_work->win );
		GF_BGL_BmpWinDel( &d_work->win );

		STRBUF_Delete(d_work->StrBuf);

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		MakeBmpList(fsys, NELEMS(DebugPkthlnMenuList), DebugPkthlnMenuList, &PkthlnDebugListWindowData, NULL);
	}
}

//AI停止フラグ表示
static void DrawEneStopFlg(DEBUG_WORK_DATA *d_work)
{
	GF_BGL_BmpWinDataFill( &d_work->win, 0x0f );
	STRBUF_SetNumber( d_work->StrBuf, DebugPkthlnWk.AI_Stop, 1, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(&d_work->win, FONT_SYSTEM, d_work->StrBuf, 0, 0, MSG_ALLPUT, NULL );
}

///////////////////////////////////////////////

//ランキングデータカンスト手前
static void SetCountStopNeary(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//データカンスト手前
	SetRnkCountStopNeary(fsys);

	//ポーズ解除
	FieldSystemProc_SeqHoldEnd();
}


static void SetRnkCountStopNeary(struct _FIELDSYS_WORK * fsys)
{
	u8 i;
	PKTHLN_SV_DATA_PTR ptr;
	PKTH_RNK_DATA *data;
	PKTH_EVT_DATA *evtdata;
	PKTH_COMM_EVT_DATA *com_evtdata;

	ptr = PkthlnSv_GetSaveData(fsys->savedata);
	data = PkthlnSv_GetRnkData(ptr);
	evtdata = PkthlnSv_GetEvtDataAlone(ptr);
	com_evtdata = PkthlnSv_GetEvtDataComm(ptr);

	data->PlayMinute = PLAY_TIME_MAX - 1;
	data->AlonePlay = ALONE_PLAY_MAX - 1;
	data->AloneWin = ALONE_WIN_MAX - 1;
	data->AloneLose = ALONE_LOSE_MAX - 1;
	data->BonusNum = BOUNUS_MAX - 1;
	data->TouchNum = TOUCH_MAX - 1;
	data->PokeFail = FAIL_MAX - 1;
	data->PokeJump = JUMP_MAX - 1;
	data->PointGet = GET_MAX - 1;
	data->PokeAttack = ATTACK_MAX - 1;
	data->PokeFall = FALL_MAX - 1;
	data->PokeDash = DASH_MAX - 1;
	data->PokeChange = CHG_MAX - 1;
	data->OwnGoal = OWN_MAX - 1;
	data->CommPlay = COMM_PLAY_MAX - 1;
	data->CommWin = COMM_WIN_MAX -1 ;
	data->CommLose = COMM_LOSE_MAX - 1;
	for(i=0;i<PKTHLN_EVT_MAX;i++){
		data->EvtWinNum[i] = EVT_WIN_MAX - 1;
	}
	data->EvtLoseNum = EVT_LOSE_MAX - 1;
	data->FunNum = FUN_MAX - 1;

	evtdata->EntryNum = ENTRY_NUM_MAX - 1;
	com_evtdata->EvtData.EntryNum = ENTRY_NUM_MAX - 1;

}


//波紋
static void DebugSub_InitWave(void *work)
{
	DBG_SAI_ST_PTR st_ptr = work;
	struct _FIELDSYS_WORK * fsys = DebugSaitoSt_GetFieldSysPtr(st_ptr);

///	DebugSaitoSt_SetWork(st_ptr, NULL);
	Wave_SetProc(fsys, NULL);
}

static void CallWave(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//ＴＢＣ作成
	st_ptr = DebugSaitoSt_AllocWork(fsys, HEAPID_BASE_DEBUG);
	DebugSaitoSt_SetFunc(st_ptr, DebugSub_InitWave);
	TCB_Add(DebugSaitoSt_FuncCall, st_ptr, 0);
}

////////////////////////////////////////////////
//記念撮影
#if 0
static void SetPictureDebugWindow(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//カメラウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugPictureMenuList),DebugPictureMenuList, &PictureDebugListWindowData, NULL);
}

//写真取る
static void TakePicture(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//写真データ作成
	FldPicture_MakeData(NULL,fsys,0,fsys->location->zone_id,
						Player_NowGPosXGet( fsys->player ),
						Player_NowGPosZGet( fsys->player ),
						0,0,0xff,0);
	OS_Printf("zone = %d, X = %d, Y = %d\n",
			fsys->location->zone_id, Player_NowGPosXGet( fsys->player ), Player_NowGPosZGet( fsys->player ));
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
}
#if 0
//写真見る
static void ViewPicture(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//写真見る
	FldPicture_SetEvent(fsys);
}
#endif
//モデル消えてる写真作る
static void TakePictureNoMdl(TCB_PTR tcb,void *work)
{
	int zone,x,z;
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//ゾーンをキキョウに
	zone = ZONE_ID_T22;
	//座標セット
	x = 487;
	z = 232;
	//写真データ作成
	FldPicture_MakeData(NULL,fsys,0,zone,x,z,
						0,0,0xff,0);
	//塔消すためにOBJ指定
	TestPicData.MdlID[0] = BMID_FIELD_KK_MADA;
	TestPicData.MdlID[1] = 0;
	TestPicData.AddObjCode = 0;
	TestPicData.RestObjID = 0xffff;
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
}

//ロケット団と一緒
static void TakePictureWithRocket(TCB_PTR tcb,void *work)
{
	int zone,x,z;
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//ゾーンをヒワダに
	zone = ZONE_ID_T23;
	//座標セット
	x = 435;
	z = 462;
	//写真データ作成
	FldPicture_MakeData(NULL,fsys,0,zone,x,z,
			 			0,0,0xff,0);
	//ロケット団指定
	TestPicData.RestObjID = T23_ROCKETM_01;
	TestPicData.AddObjCode = 0;
	TestPicData.MdlID[0] = 0;
	TestPicData.MdlID[1] = 0;
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
}

//ジムリーダーと一緒
static void TakePictureWithLeader(TCB_PTR tcb,void *work)
{
	int zone,x,z;
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	//ゾーンを自然公園
	zone = ZONE_ID_D22R0101;
	//座標セット
	x = 51;
	z = 47;
	//写真データ作成
	FldPicture_MakeData(NULL,fsys,0,zone,x,z,
						0,0,0xff,0);
	//リーダーセット
	TestPicData.AddObjCode = GSLEADER1;
	TestPicData.RestObjID = 0xffff;
	TestPicData.MdlID[0] = 0;
	TestPicData.MdlID[1] = 0;

	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();
}
#endif

////////////////////////////////////////////////
#define	GROUND_ID_ALL		(12)	//それ以外（一応定義）戦闘defから引用
#include "itemtool/itemsym.h"
//3体選択
static void DebugSub_InitPokeSelect(void *work)
{
	int i;
	POKESELECT_PEARENT_DATA *parent;
	DBG_SAI_ST_PTR st_ptr = work;
	struct _FIELDSYS_WORK * fsys = DebugSaitoSt_GetFieldSysPtr(st_ptr);
	int first_mons_no[3] = {152,155,158};
	int level = 5;
	u16 itemno = 0;
	int place_id = ZoneData_GetPlaceNameID(fsys->location->zone_id);
	int ground_id = GROUND_ID_ALL;
	int heap = HEAPID_BASE_DEBUG;

	parent = sys_AllocMemory(heap,sizeof(POKESELECT_PEARENT_DATA));
	parent->Config = SaveData_GetConfig( fsys->savedata );
	//手持ちに加える3体のポケデータの作成
	for (i=0;i<3;i++){
		BOOL result;
		POKEMON_PARAM *poke_param;
		u32 buf;
		MYSTATUS * my;

		poke_param = &parent->PokeParam[i];
		my = SaveData_GetMyStatus(fsys->savedata);
//		poke_param = PokemonParam_AllocWork(heap);
		PokeParaInit(poke_param);
		PokeParaSet(poke_param, first_mons_no[i], level, POW_RND, RND_NO_SET, 0, ID_NO_SET, 0);
		PokeParaGetInfoSet(poke_param, my, ITEM_MONSUTAABOORU, place_id, ground_id, heap);
		buf = itemno;
		PokeParaPut(poke_param, ID_PARA_item, &buf);
	}

	DebugSaitoSt_SetWork(st_ptr, parent);
	FirstPokeSelect_SetProc(fsys, parent);
}

//3体選択呼び出し
static void CallPokeSelect(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	DebugSetPokeSelEvent(fsys);

/**
	//3対選択用ＴＢＣ作成
	st_ptr = DebugSaitoSt_AllocWork(fsys, HEAPID_BASE_DEBUG);
	DebugSaitoSt_SetFunc(st_ptr, DebugSub_InitPokeSelect);
	TCB_Add(DebugSaitoSt_FuncCall, st_ptr, 0);
*/
}

////////////////////////////////////////////////
//ロケット団に変装
static void ChangeRocket(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;


	if( Player_FormGet(fsys->player) == HERO_FORM_ROCKET ){
		Player_RequestSet( fsys->player, HERO_REQBIT_NORMAL );
		Player_FormSet( fsys->player, HERO_FORM_NORMAL );
	}else{
		Player_RequestSet( fsys->player, HERO_REQBIT_ROCKET );
		Player_FormSet( fsys->player, HERO_FORM_ROCKET );
	}

	DebugWindowExit(tcb,work);

}

//リニアメニュー(街選択)
#if 0
static void DebugWinLinear(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugLinearMenuList), DebugLinearMenuList, &PkthlnDebugListWindowData, NULL);
}


//リニア呼び出し
static void CallLinearDemoK(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	DebugSetLinearEvent(fsys, 0);
}

static void CallLinearDemoY(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	DebugSetLinearEvent(fsys, 1);
}

//船メニュー(街選択)
static void DebugWinShip(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();
	//ウィンドウ構築
	MakeBmpList(fsys, NELEMS(DebugShipMenuList), DebugShipMenuList, &PkthlnDebugListWindowData, NULL);
}


//船呼び出し
static void CallShipDemoA(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	DebugSetShipEvent(fsys, 0);
}

static void CallShipDemoK(TCB_PTR tcb,void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;

	DBG_SAI_ST_PTR st_ptr;

	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);

	DebugSetShipEvent(fsys, 1);
}
#endif

////////////////////////////////////////////////
//連れ歩きビューア
static void SetPairPokeViewMode(TCB_PTR tcb,void *work)
{
	//モード切替
	PairPokeDbg.ViewMode = (PairPokeDbg.ViewMode+1)%2;
	DebugWindowExit(tcb,work);
}


//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケグラフィック変更イベント
 *
 * @param	event	イベントポインタ
 *
 * @return	BOOL
 */
//--------------------------------------------------------------------------------------------
static BOOL ChangePairPokeEvt(GMEVENT_CONTROL * event)
{
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	int * seq = FieldEvent_GetSeqWork(event);
	switch(*seq){
	case 0:
		{
			int code;
			code = FieldOBJ_OBJCodeGet( fsys->PairPokeWork.FldObj );
			code += PairPokeDbg.AddVal;
			if ( code < PAIR_POKE_CODEORG){
				code = PAIR_POKE_CODE_END;
			}else if(code >PAIR_POKE_CODE_END){
				code = PAIR_POKE_CODEORG;
			}

			FieldOBJ_BlActDummyDrawReset( fsys->PairPokeWork.FldObj, code );
		}
		(*seq)++;
	case 1:
		if (FieldOBJ_BlActAddPracFlagCheck(fsys->PairPokeWork.FldObj)==FALSE ){
			return TRUE;
		}
		break;
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケカラー変更イベント
 *
 * @param	event	イベントポインタ
 *
 * @return	BOOL
 */
//--------------------------------------------------------------------------------------------
static BOOL ChangePairPokeColEvt(GMEVENT_CONTROL * event)
{
	FIELDSYS_WORK * fsys = FieldEvent_GetFieldSysWork(event);
	int * seq = FieldEvent_GetSeqWork(event);
	switch(*seq){
	case 0:
		{
			FIELD_OBJ_PTR fldobj = fsys->PairPokeWork.FldObj;
			CONST_FIELD_OBJ_SYS_PTR fos =  FieldOBJ_FieldOBJSysGet( fldobj );
			if (PairPokeDbg.Rare == 0){
				PairPokeDbg.Rare = 1;
			}else{
				PairPokeDbg.Rare = 0;
			}
			PairPoke_SetColor(PairPokeDbg.Rare, fldobj,	FldOBJ_GetPairPokeAct(fos));
			//連れ歩きを下向きでセット
			PairPoke_SetDir(fsys, DIR_DOWN);

		}
		(*seq)++;
	case 1:
		return TRUE;
		break;
	}
	return FALSE;
}


//--------------------------------------------------------------------------------------------
/**
 * イベントセット
 *
 * @param	fsys	フィールドシステムポインタ
 *
 * @return	BOOL
 */
//--------------------------------------------------------------------------------------------
BOOL Debug_SetPokeChgEvent(FIELDSYS_WORK * fsys, int trg)
{
	BOOL rc = FALSE;
	if ( PairPokeDbg.ViewMode ){
		if (trg & PAD_BUTTON_L){
			PairPokeDbg.AddVal = -1;
			FieldEvent_Set(fsys, ChangePairPokeEvt, NULL);
			rc = TRUE;
		}else if (trg & PAD_BUTTON_R){
			PairPokeDbg.AddVal = 1;
			FieldEvent_Set(fsys, ChangePairPokeEvt, NULL);
			rc = TRUE;
		}else if (trg & PAD_BUTTON_SELECT){
			PairPokeDbg.AddVal = -10;
			FieldEvent_Set(fsys, ChangePairPokeEvt, NULL);
			rc = TRUE;
		}else if (trg & PAD_BUTTON_START){
			PairPokeDbg.AddVal = 10;
			FieldEvent_Set(fsys, ChangePairPokeEvt, NULL);
			rc = TRUE;
		}else if(trg & PAD_BUTTON_B){
			FieldEvent_Set(fsys, ChangePairPokeColEvt, NULL);
			rc = TRUE;
		}
	}
	return rc;
}

//-----------------------------------------------------------------
//--伝説系フィールドデモ
//
//
static void SetFldLegDemoFlg(TCB_PTR tcb, void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();

	SetFldLegDemoFlgWindow(fsys);
}

//伝説系フィールドデモ用ウィンドウ構築
static void SetFldLegDemoFlgWindow(struct _FIELDSYS_WORK * fsys)
{

	DEBUG_WORK_DATA *wk = NULL;

	TCB_PTR	pTcb = NULL;
	wk = sys_AllocMemory(HEAPID_D_SAITO,sizeof(DEBUG_WORK_DATA));
	wk->fsys = fsys;
	//メイン処理タスク追加
	pTcb = TCB_Add(FldLegDemoFlgTask, wk, 0);

	GF_BGL_BmpWinAdd( wk->fsys->bgl,&wk->win,GF_BGL_FRAME3_M, 0, 0, 9, 2, 1, 1 );

	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 16<<1, HEAPID_D_SAITO );
	//フラグ表示
	DrawFldLegFlg(wk);
	return;
}

//伝説系フィールドデモウィンドウ表示中タスク
static void FldLegDemoFlgTask(TCB_PTR tcb,void* work)
{
	u8 flg_no;
	BOOL end;
	BOOL redraw;
	DEBUG_WORK_DATA *wk = (DEBUG_WORK_DATA *)work;

	end = FALSE;
	redraw = FALSE;

	if (sys.trg & PAD_KEY_RIGHT){
		flg_no = DebugLegFldDemoFlg;
		if (flg_no == 2 ){
			flg_no = 0;
		}else{
			flg_no++;
		}
		DebugLegFldDemoFlg = flg_no;
		redraw = TRUE;
	}else if (sys.trg & PAD_KEY_LEFT){
		flg_no = DebugLegFldDemoFlg;
		if (flg_no == 0){
			flg_no = 2;
		}else{
			flg_no--;
		}
		DebugLegFldDemoFlg = flg_no;
		redraw = TRUE;
	}else if ( (sys.trg & PAD_BUTTON_B)||(sys.trg & PAD_BUTTON_A) ){
		end = TRUE;
	}

	if (redraw){
		DrawFldLegFlg(wk);
	}

	if (end){
		struct _FIELDSYS_WORK * fsys;
		fsys = wk->fsys;

		GF_BGL_BmpWinOff( &wk->win );
		GF_BGL_BmpWinDel( &wk->win );

		sys_FreeMemoryEz((void *)work);
		//タスク消去
		TCB_Delete(tcb);
		//OBJ等の動作停止解除
		FieldSystemProc_SeqHoldEnd();
	}
}

//伝説系フィールドデモフラグ表示
static void DrawFldLegFlg(DEBUG_WORK_DATA *wk)
{
	int msg_code;
	STRBUF *msg_buf;
	MSGDATA_MANAGER* man;

	GF_BGL_BmpWinDataFill( &wk->win, 0x0f );

	man = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_saito_dat, HEAPID_D_SAITO);
	msg_buf = STRBUF_Create(40,HEAPID_D_SAITO);

	if (DebugLegFldDemoFlg == 2){
		msg_code = D_SAITO_ROM_VER_SLV;
	}else if(DebugLegFldDemoFlg == 1){
		msg_code = D_SAITO_ROM_VER_GLD;
	}else {
		msg_code = D_SAITO_ROM_VER_NRM;
	}

	MSGMAN_GetString(man, msg_code ,msg_buf);
	GF_STR_PrintSimple(&wk->win, FONT_SYSTEM, msg_buf, 1*8, 0, MSG_ALLPUT, NULL );

	STRBUF_Delete( msg_buf );
	MSGMAN_Delete( man );

	GF_BGL_BmpWinOn( &wk->win );
}


extern void DPP_MakeBmpList(struct _FIELDSYS_WORK *fsys, OVERLAY_CALL_BACK callback);
//-----------------------------------------------------------------
//--連れ歩きパラメータデバッグ
//
//
static void DebugPairPoke(TCB_PTR tcb, void *work)
{
	struct _FIELDSYS_WORK * fsys;
	DEBUG_WINDOW_DATA *wp;
	wp = (DEBUG_WINDOW_DATA *)work;
	fsys = wp->fsys;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();

	{
		OS_Printf("連れ歩きデバッグオーバーレイロード\n");
		Overlay_Load( FS_OVERLAY_ID( debug_pair_poke ), OVERLAY_LOAD_NOT_SYNCHRONIZE );
		DPP_MakeBmpList(fsys, DebugPairPokeOverlayCB);
	}
}

static void DebugPairPokeOverlayCB(void)
{
	//アンロード
	OS_Printf("連れ歩きデバッグオーバーレイアンロード\n");
	Overlay_UnloadID( FS_OVERLAY_ID( debug_pair_poke ) );
}

#endif	//#ifdef PM_DEBUG